0
我有我的listview活動工作得很好,但我有一個惱人的問題。 無論何時恢復,它都會在列表中添加相同的項目,並且這個項目會變得更大。我只是想讓它保持我首先想到的價值。 我該怎麼做? 這裏是我的活動ListView,防止添加新項目
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list_view);
adapter = new SimpleAdapter(
this,
list,
R.layout.custom_row_view,
new String[] {"pen","price","color"},
new int[] {R.id.text1,R.id.text2, R.id.text3}
);
populateList();
setListAdapter(adapter);
}
這裏是我的ArrayList:
static final ArrayList<LinkedHashMap<String,String>> list =
new ArrayList<LinkedHashMap<String,String>>();
private void populateList() {
LinkedHashMap<String,String> temp = new LinkedHashMap<String,String>();
temp.put("pen"," Mission name");
list.add(temp);
LinkedHashMap<String,String> temp1 = new LinkedHashMap<String,String>();
temp1.put("pen"," Map activity");
list.add(temp1);
LinkedHashMap<String,String> temp2 = new LinkedHashMap<String,String>();
temp2.put("pen"," Check sensors");
list.add(temp2);
LinkedHashMap<String,String> temp3 = new LinkedHashMap<String,String>();
temp3.put("pen"," Infrared Image");
list.add(temp3);
LinkedHashMap<String,String> temp4 = new LinkedHashMap<String,String>();
temp4.put("pen"," Radar Image");
list.add(temp4);
LinkedHashMap<String,String> temp5 = new LinkedHashMap<String,String>();
temp5.put("pen"," Visual image");
list.add(temp5);
LinkedHashMap<String,String> temp6 = new LinkedHashMap<String,String>();
temp6.put("pen"," suscribe to Viewer");
list.add(temp6);
}
防止手段...? – 2012-02-28 17:45:17
我的意思是保留它來添加相同的物品 – youssoua 2012-02-28 17:53:55