我有一个ListView。 我从2个editTexts填充此列表 当我移动活动并返回时,条目再次消失。 我有点理解这是为什么,但不知道如何纠正它。当我移动活动时保持列表条目
ListView lv2 = (ListView) findViewById(R.id.listView2);
final SimpleAdapter simpleAdpt = new SimpleAdapter(this, planetsList, android.R.layout.simple_list_item_1, new String[]{"planet"}, new int[]{android.R.id.text1});
planetsList.add(createPlanet("planet", "testme"));
lv2.setAdapter(simpleAdpt);
button21.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
iinitList();
simpleAdpt.notifyDataSetChanged();
editText5.setText("");
editText6.setText("");
}
});
}
private void iinitList() {
String st,str;
Double db;
if (editText5.getText().toString()!= "" && editText6.getText().toString()!="") {
st = editText5.getText().toString();
str = editText6.getText().toString();
db = Double.parseDouble(str);
planetsList.add(createPlanet("planet", ""+st+
": \n" +db+""));
}
}
HashMap<String, String> createPlanet(String key, String name) {
HashMap<String, String> planet = new HashMap<String, String>();
planet.put(key, name);
return planet;
}
正如你可以看到我已经添加值的手动名为test也榜上有名,当我移动活动这个停留在列表中,我想如果EDITTEXT条目都留在那里还当我移动爱活动。
,那么你必须将它保存[莫名其妙](http://developer.android.com/guide/topics/data/data-storage。 html)... – Selvin 2015-04-03 13:36:41