我做了这个简单的应用程序,在这个应用程序中,当我单击开始按钮时,我想查看其中的数据Listview
,但它不起作用。你能帮助我吗?
mainActivity.java
public class MainActivity extends ListActivity {
public ArrayList<Map<String, String>> list= new ArrayList<Map<String, String>>();
public ListAdapter adapter;
public ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonAggiorna = (Button) findViewById(R.id.buttonStart);
buttonAggiorna.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String[] from = { "name", "purpose" };
int[] to = { android.R.id.text1, android.R.id.text2 };
adapter = new SimpleAdapter(MainActivity.this, list,android.R.layout.simple_list_item_2, from, to);
progressDialog = ProgressDialog.show(MainActivity.this, "Getting data", "Loading...");
taskBack t=new taskBack();
t.execute();
}
});// fine onClickListner
Button buttonAllarm = (Button) findViewById(R.id.buttonAllarm);
buttonAllarm.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
AppLog.logString("list size:"+list.size());
}
});
}
private class taskBack
extends AsyncTask<Void, Void, ArrayList<Map<String, String>>> {
@Override
protected ArrayList<Map<String, String>> doInBackground(Void... arg0) {
ArrayList<Map<String, String>> l = new ArrayList<Map<String, String>>();
l = startEla();
return l;
}
protected void onPostExecute(ArrayList<Map<String, String>> result) {
AppLog.logString("Parte onPostExecute");
list=result;
setListAdapter(adapter);
progressDialog.dismiss();
}
private ArrayList<Map<String, String>> startEla() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(putData("android","mobile"));
list.add(putData("Windows7", "Windows7"));
list.add(putData("iPhone", "iPhone"));
return list;
}
private Map<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
return item;
}
}
}
在此链接中,您可以看到 xml 文件在此处输入链接描述
最好的问候 A.