小弟初学确实不知道怎么做跪求各位指点:
activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project_main);
sb.append("http://w.gy-center.net/app/json.php?module=project&page=1");
String path=sb.toString();
List<HashMap<String,Object>> list =new ArrayList<HashMap<String,Object>>();
listView = (ListView) this.findViewById(R.id.viewId);
////////调用工具类
AsyncTaskHttp asyncTaskHttp=new AsyncTaskHttp();
asyncTaskHttp.execute();
///////////////
SimpleAdapter adapter=new SimpleAdapter
(this, list, R.layout.projiect_listview, new String[]{"id","title","date"},
new int[]
{R.id.projectID,R.id.projectTitleID,R.id.projectDateID});
listView.setAdapter(adapter);
}
AsyncTaskHttp 工具类 用于异步获取数据:
public class AsyncTaskHttp extends AsyncTask<String, String, List>{
@Override
protected void onPreExecute() {
//弹出一个对话框
proDialog=new ProgressDialog(context);
proDialog.setTitle("加载信息");
proDialog.setMessage("信息加载中,请稍后...");
proDialog.onStart();
proDialog.show();
}
@Override
protected List doInBackground(String... path) {
List list=new ArrayList();
try {
list = JsonService.getJson(path[0]);//获取数据返回一个集合
} catch (Exception e) {
}
return list;
}
@Override
protected void onPostExecute(List result) {
//如何绑定数据呢这里?????????
//关闭对话框
proDialog.dismiss();
}
}
listview asynctask
------解决方案--------------------
activity中写一个setList方法
void setList(List input){
this.list = input
}
AsyncTaskHttp重载一个构造方法,并加入一个成员变量。
AsyncTaskHttp(Activity a){
super();
this.activity = a;
}
protected void onPostExecute(List result) {
//如何绑定数据呢这里?????????
a.setList(result);
//关闭对话框
proDialog.dismiss();
}
在activity中。每当调用了aysnctask.execute的时候,记得调用adapter.notifychanged方法进行刷新。
------解决方案--------------------