SimpleAdapter
を表示するために使用しListView
ていますが、戻るボタンを押してアクティビティ(リストを表示)を再度開くと、リストのエントリが2倍になります。
もう一度行うと、配列値はリストの項目と再び連結されます。
配列のリスト変数は次のように宣言されています
private static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
onCreate()
の私のコードList.java
:
setContentView(R.layout.list);
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("first","Strength");
temp.put("second", strength);
list.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("first","what");
temp1.put("second", "??");
list.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("first","Time");
temp2.put("second", "time");
list.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("first","Repeat");
temp3.put("second", "everyday");
list.add(temp3);
setListAdapter(new SimpleAdapter(this,list,R.layout.row_view, new String [] {"first","second"}, new int [] {R.id.rowTextView1, R.id.rowTextView2} ));