异步加载数据
来源:互联网 发布:网络宣传公司 编辑:程序博客网 时间:2024/04/30 15:37
class MyAsycTask extends AsyncTask<String, String, News> {@Overrideprotected News doInBackground(String... params) {// TODO Auto-generated method stubreturn getNews(params[0]);}@Overrideprotected void onPostExecute(final News news) {super.onPostExecute(news);lv.setAdapter(new MyLvAdapter(MainActivity.this, news));lv.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {Intent intent=new Intent(MainActivity.this, DetailActivity.class);intent.putExtra("id", news.data.get(arg2).ID);startActivity(intent);}});}}/*** 解析获得数据** @param string* @return*/public News getNews(String string) {try {URL url = new URL(string);HttpURLConnection openConnection = (HttpURLConnection) url.openConnection();openConnection.setConnectTimeout(5000);int responseCode = openConnection.getResponseCode();if (responseCode == 200) {InputStream inputStream = openConnection.getInputStream();byte[] arr = new byte[1024];int len;ByteArrayOutputStream stream = new ByteArrayOutputStream();while ((len = inputStream.read(arr)) != -1) {stream.write(arr, 0, len);}String json = stream.toString();Gson gson = new Gson();News news = gson.fromJson(json, News.class);return news;}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}
0 0
- 数据异步加载
- 数据异步加载(转帖)
- 数据异步加载
- 异步加载数据库数据
- 异步交互加载数据
- 异步加载网络数据
- 异步加载数据
- AsyncTask异步加载数据
- ztree异步加载数据
- 异步加载数据
- AsyncTask异步加载数据
- 使用Loaders异步加载数据
- 使用CursorLoader异步加载数据
- 异步加载图片等数据
- ListView异步加载网络数据
- 使用CursorLoader异步加载数据
- Ext Tree 异步加载数据
- 使用BeginExecuteReader异步加载数据
- Android中的几种对话框(AlertDialog)
- Instant Client 下安装 sqlldr
- JS实现回到顶部按钮
- Tensorflow: Convolutional Neural Network Basic
- 一个小白从零基础自学Android编程笔记之如何设置EidtText的边框
- 异步加载数据
- 数据库范式
- Jackson json 处理全大写或不规范的JSON
- How to integrate ZXing Library to Android Studio for Barcode Scanning?
- IntelliJ IDEA 运行你的第一个Java应用程序
- background-position 用法详细介绍
- hdu 4824 Disk Schedule 双调欧几里得 (TSP类)
- 回到顶部实用代码
- JS事件