• AsyncTask异步交互


    package com.baidu.day06asynctask;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.baidu.adapter.MyAdapter;
    import com.baidu.mynetutil.NewUtil;
    import com.baidu.vo.MyData;
    import com.baidu.vo.SuperFrist;
    import com.google.gson.Gson;
    
    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.widget.ListView;
    
    public class ShowActivity extends Activity{
        private ListView listView;
    
        @Override
        protected void onCreate(Bundle arg0) {
            // TODO Auto-generated method stub
            super.onCreate(arg0);
            setContentView(R.layout.activity_show);
            init();
        }
    
        private void init() {
            //找到相应的控件
            listView = (ListView) findViewById(R.id.lv);
            if(NewUtil.Netisavilable(ShowActivity.this)){
                
                new MyAsyncTask().execute(NewUtil.jSON_URL);
            }
            
        }
        class MyAsyncTask extends AsyncTask<String,Integer,String>{
    
            private List<MyData> list;
            @Override
            protected String doInBackground(String... arg0) {
                String str=arg0[0];
                String jstr=NewUtil.Check_Json(str);
                return jstr;
            }
            @Override
            protected void onPostExecute(String result) {
                //解析json
                Gson g=new Gson();
                SuperFrist sf=g.fromJson(result, SuperFrist.class);
                //创建一个集合容器
                list = sf.getResult().getData();
                //创建适配器
                listView.setAdapter(new MyAdapter(ShowActivity.this,list));
                super.onPostExecute(result);
            }
            
        }
    
    }
  • 相关阅读:
    DTS和AC3的区别
    bind出现 file does not end with newline错误
    删除桌面菜单多余项
    you have requested a nonexistent service "grid"
    php 常用函数
    Jquery
    Twig 的Filters学习
    Twig 的 tags学习(中文) 之三 完结
    PHP 正则表达式
    SQL处理字符串
  • 原文地址:https://www.cnblogs.com/1995yu/p/5447585.html
Copyright © 2020-2023  润新知