//activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.huoqu.MainActivity"><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"><Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="getNetLv"
            android:text="HttpClient请求" /><Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="getNetLv"
            android:text="HttpURLConnection请求" /></LinearLayout><ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
//list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"><ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher" /><TextView
        android:id="@+id/title"
        android:layout_width="340dp"
        android:layout_height="100dp"
        android:text="正在加载..." /></LinearLayout>
//MainActivity
package com.example.huoqu;import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;import com.google.gson.Gson;import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;public class MainActivity extends AppCompatActivity {private ListView lv;private List<JsonBean.NewslistBean> lists;@Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);lv = (ListView) findViewById(R.id.lv);}public void getNetLv(View v) {new Thread() {@Override
            public void run() {requestgetNetLv();}}.start();}private void requestgetNetLv() {new MyasyncTask().execute("https://api.tianapi.com/wxnew/?key=8d6e3228d25298f13af4fc40ce6c9679&num=10");}class MyasyncTask extends AsyncTask<String, Void, String> {@Override
        protected String doInBackground(String... strings) {try {URL url = new URL(strings[0]);HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();int responseCode = urlConnection.getResponseCode();if (responseCode == 200) {InputStream inputStream = urlConnection.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));StringBuffer buffer = new StringBuffer();String str = "";while ((str = reader.readLine()) != null) {buffer.append(str);}return buffer.toString();}} catch (Exception e) {e.printStackTrace();}return null;}@Override
        protected void onPostExecute(String s) {super.onPostExecute(s);Gson gson = new Gson();JsonBean jsonBean = gson.fromJson(s, JsonBean.class);lists = jsonBean.getNewslist();MyAdapter myAdapter = new MyAdapter();lv.setAdapter(myAdapter);}}class MyAdapter extends BaseAdapter {@Override
        public int getCount() {return lists.size();}@Override
        public Object getItem(int i) {return lists.get(i);}@Override
        public long getItemId(int i) {return i;}@Override
        public View getView(int i, View view, ViewGroup viewGroup) {ViewHowder vh;if (view == null) {view = View.inflate(MainActivity.this, R.layout.list_item, null);vh = new ViewHowder();vh.image = view.findViewById(R.id.image);vh.title = view.findViewById(R.id.title);view.setTag(vh);} else {vh = (ViewHowder) view.getTag();}vh.title.setText(lists.get(i).getTitle());new MAsyncTaskImage(vh.image).execute(lists.get(i).getPicUrl());return view;}class MAsyncTaskImage extends AsyncTask<String, Void, Bitmap> {private ImageView imageView;public MAsyncTaskImage(ImageView imageView) {this.imageView = imageView;}@Override
            protected Bitmap doInBackground(String... strings) {try {URL url = new URL(strings[0]);HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();int responseCode = urlConnection.getResponseCode();if (responseCode == 200) {InputStream inputStream = urlConnection.getInputStream();Bitmap bitmap = BitmapFactory.decodeStream(inputStream);return bitmap;}} catch (Exception e) {e.printStackTrace();}return null;}@Override
            protected void onPostExecute(Bitmap bitmap) {super.onPostExecute(bitmap);imageView.setImageBitmap(bitmap);}}class ViewHowder {ImageView image;TextView title;}}
}
//JsonBean
package com.example.huoqu;import java.util.List;/**
 * Created by 一生不羁放纵 on 2017/9/28 0028.
 */

public class JsonBean {/**
     * code : 200
     * msg : success
     * newslist : [{"ctime":"2017-09-28","title":"我问自己!(瞬间醒脑)","description":"镜界乐享","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49492447.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582024&signature=Eosq-Osp7sxuLBBjfH*zIbqcnzK8jUdp0-cVwfDXCtXSEc-skSkfeLibUsoCnJ-HQnFeeZtqF6ArdzraOz8gIhIa58rMlzjOK1NcuPH57iw="},{"ctime":"2017-09-28","title":"心灵短片《微笑的力量》,看完整个人都治愈了","description":"镜界乐享","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-36941491.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582024&signature=sf0L7HUYgksoWa3TVPi-0MfrpqYjRxG8ytPJpyMSJ39giH1ooPbFizD9mKRR9q7-UgQfefgvMjVVn*6k3yZpJaMGZp-QY8kpQsvAGe0ZxII="},{"ctime":"2017-09-28","title":"善良,永不过期;好心,必有好报","description":"猩灵砒霜","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-45741685.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582023&signature=zDy24MDX-g1O-uWVRsr5OuSoDljho8i3cPMGa2fJN3ii2mtNVKMbtRunYyFo9G7m4iUONcjsn24CZeZkEjANWPzoO8NI0A35vlplUyNx5lM="},{"ctime":"2017-09-28","title":"中秋礼物 | 《莲若》聆听古音天籁,感受千年风雅","description":"瑜伽导师营","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-46940733.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582023&signature=KscWCwwYvjrF6KDZW*DiQUI1HrqvUJ9EOFn3CoUWmdB*KNyYGxz4-0s3TRBFQvMck3f-0rp9ApbkBOScqByY*aIOEd*gr4TUKXWb0XIVQiQ="},{"ctime":"2017-09-28","title":"30岁左右的人都应该明白这个道理","description":"亲宝宝育儿","picUrl":"https://t1.qpic.cn/mblogpic/34d9dfb75cfceb04a840/2000","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582023&signature=RLOg-Y6PBdheOuMoy6JbL5QR8GlFw5Tn0bCxFA7kir7R0OmUyUKAkkYLwhHduZ0BfOK8ANM0ZGdJTNKhEwqecEkHeSbViTuNr7kXdjJ1nPU="},{"ctime":"2017-09-28","title":"不懂得好好说话的家庭,养不出幸福的孩子","description":"亲宝宝育儿","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49490916.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582022&signature=Gl0GABKImphRvUUXbxk0h0j4I9fIkWcBKfk6bO1cZPXVHZNUW*S9LtBZIIbj3sg5oryKJPZ9xx0A0QzaS*EDOnvGMx5TdCFcNE0AGWXcBNw="},{"ctime":"2017-09-28","title":"赠你一场秋声,答你一个永远","description":"遇见散文诗歌","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49488341.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582022&signature=XnDijk-h*HwYUkJH1sejb4wNvGHZkvJfmfOuEWD9STlVvJWbT*uFlIn5a9wExR9lVUQN509BvfqA3VWC1yjye24P1TZqtXQImUVkrXpKQtQ="},{"ctime":"2017-09-28","title":"顺境善待别人,逆境善待自己。","description":"遇见散文诗歌","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49489224.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582022&signature=A2HEdNX-ERvBhXWRlvzuXRRdcfWnyC4bhM6NSl0vNsgtycJH-8sruu95U4*jtLoTRChz6ochzqIC5HIORFzCdwE4l2I7zxror96uJUYNKcw="},{"ctime":"2017-09-28","title":"【朗诵】一程遇见,一念安好","description":"遇见散文诗歌","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49489213.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582022&signature=KsfgupYcQp3M-SawpYYQ4TdpTe4O2PjWfnRJuWnfFOybmAFvt39FtFwHPpPFIsT-wcdS-ZiHAHcVhtNQB6pVe8JXGyHVP5DUZoHMAMTPtg4="},{"ctime":"2017-09-28","title":"【朗诵】有一种陪伴,一直在心间","description":"遇见散文诗歌","picUrl":"https://zxpic.gtimg.com/infonew/0/wechat_pics_-49489243.jpg/640","url":"https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582021&signature=c6Pckue5CUvj1RTcz9zS3FtguVqRiRz-Gg4XyxPmHf7YblF8rm5xjC3lcpGGzSDtRU-KSCY7resdY38RYoJ5q0dTMGgXa1frrOQGH4HCW9A="}]
     */

    private int code;private String msg;private List<NewslistBean> newslist;public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public List<NewslistBean> getNewslist() {return newslist;}public void setNewslist(List<NewslistBean> newslist) {this.newslist = newslist;}public static class NewslistBean {/**
         * ctime : 2017-09-28
         * title : 我问自己!(瞬间醒脑)
         * description : 镜界乐享
         * picUrl : https://zxpic.gtimg.com/infonew/0/wechat_pics_-49492447.jpg/640
         * url : https://mp.weixin.qq.com/s?src=16&ver=394&timestamp=1506582024&signature=Eosq-Osp7sxuLBBjfH*zIbqcnzK8jUdp0-cVwfDXCtXSEc-skSkfeLibUsoCnJ-HQnFeeZtqF6ArdzraOz8gIhIa58rMlzjOK1NcuPH57iw=
         */

        private String ctime;private String title;private String description;private String picUrl;private String url;public String getCtime() {return ctime;}public void setCtime(String ctime) {this.ctime = ctime;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getPicUrl() {return picUrl;}public void setPicUrl(String picUrl) {this.picUrl = picUrl;}public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}}
}

点击按钮获取listview网上数据相关推荐

  1. 微信小程序开发——点击按钮获取用户授权没反应或反应很慢的解决方法

    微信小程序开发--点击按钮获取用户授权没反应或反应很慢的解决方法 参考文章: (1)微信小程序开发--点击按钮获取用户授权没反应或反应很慢的解决方法 (2)https://www.cnblogs.co ...

  2. 关于设置table样式后,不停点击按钮table中的数据会逐渐被最后一行替换的问题...

    方法1:初始化htmlTable中的数据,table中有两行表头,其页面写法是: <table id="MyTable" runat="server"&g ...

  3. jq点击按钮获取php的值删除,通过jquery怎么移除点击事件

    通过jquery移除点击事件的方法:首先在html里添加一个按钮:然后使用jquery来为按钮添加上click的点击事件:最后使用jquery的unbind方法来移除事件就行了. 本教程操作环境:wi ...

  4. 点击刷新按钮实现listview的数据刷新

    本功能因为,没有从第三方获取到信息,所以,本章就是用了插入固定数据,使用了javabean的技术来实现插入固定的数据,再通过adapter将数据插入到listview中,最后使用thread和hand ...

  5. html点击按钮获取列表数据传递到页面,随笔:ajax传递数组,layui父子页面传值,下来菜单赋值,父页面数据获取,表格数据替换为字符串...

    一.Ajax向后台传递数组问题:(声明前台我使用的layui框架) 例:我们要多前台一个数据表格进行批量删除操作,我们通过复选框选中数据id,将id存入一个数组中,然后利用ajax传递给后台,完成批量 ...

  6. Android中点击按钮获取string.xml中内容并弹窗提示

    场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...

  7. html网页获取点击按钮获取当前时间

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Android中点击按钮获取星级评分条的评分

    场景 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为Lin ...

  9. 点击按钮创建一个表格 点击按钮创建一个表格 权限选择 元素的value属性操作

    点击按钮创建一个表格 <!DOCTYPE html> <html lang="en"> <head><meta charset=" ...

最新文章

  1. Camera Calibration 相机标定
  2. 2018年第一场省赛:黑龙江省智能车邀请赛
  3. python 中使用celery
  4. JavaScript内存泄漏知多少?
  5. 关于JAP FetchType.LAZY(hibernate实现)的理解
  6. CSS中的块元素,内联元素,内联块元素
  7. Systemd入门教程:命令篇
  8. SpringSecurity Filter
  9. 可视化与办公自动化学习
  10. 你会想待下去吗?世界上25个最惊险的屋顶
  11. 7 款神秘的开源中间件!
  12. Android NDK 入门与实践
  13. java套接字实验总结,实验三、WINSOCK套接字编程实验报告
  14. [阅读笔记]Modern C++ Programming with Test-Driven Develpment chp2
  15. 学习笔记-Matlab算法篇-动态规划
  16. MySQL8.0下载及安装教程
  17. myeclipse 10破解方法
  18. java的class是什么意思_Java的class是什么意思?
  19. 转换word等文件为swf文件
  20. Whistle pc抓包,手机抓包,https抓包

热门文章

  1. 使用VBA如何将中文字符转换为区位码
  2. CSS入门系列(一)概述和html结合的方式
  3. 分享一个麻将听牌算法(带癞子)(Lua)
  4. DM达梦数据库使用druid时提示:dbType not support : dm
  5. opencv:centos7中安装opencv4.3.0环境
  6. 什么人不在生死簿_人的生死簿-地府中类似于生死簿的东西有哪些/地府中类似于生死簿,-爱问知识人...
  7. [软工导论①]复习题库
  8. Wireshark搜索关键字内容
  9. PCIe4.0的Add-in-Card(AIC)金手指layout建议
  10. 手机端网页监测是否打开键盘