我正在开发一个应用程序,并且我在一个屏幕中有一个列表视图,因为我正在使用类传递值。在listview
的项目单击事件上,它会打开用于选择值的活动。我将这个值保存到SharedPrefrence
我想要这些数据到另一个活动中。它将值存储到SharedPreference
. 但它不会listview
在返回活动时更新。但我正在更新 List onCreate()
。
try{
selectedParentMessage = ParentMessageListActivity.parentMsgSharedPref.getString("SelectedParentMessage", "None");
System.out.println("Selected Parent Message:"+selectedParentMessage);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
items.add(new Setting_ActivitySectionItem("Sounds"));
//items.add(new Setting_ActivityEntryItem("Cartoon's Voice", ""));
items.add(new Setting_ActivityEntryItem("Record Parent's Message", ""+selectedParentMessage));
items.add(new Setting_ActivityEntryItem("Import Lullaby", ""));
items.add(new Setting_ActivitySectionItem("Alerts"));
items.add(new Setting_ActivityEntryItem("Phone Number", ""));
items.add(new Setting_ActivityEntryItem("Email Id", ""));
items.add(new Setting_ActivityEntryItem("Send Notification", ""));
//items.add(new EntryItem("Item 7", "This is item 2.4"));
items.add(new Setting_ActivitySectionItem("Baby's Noise Level"));
items.add(new Setting_ActivityEntryItem("High", ""));
items.add(new Setting_ActivityEntryItem("Medium", ""));
items.add(new Setting_ActivityEntryItem("Low", ""));
//items.add(new EntryItem("Item 11", "This is item 3.4"));
//items.add(new EntryItem("Item 12", "This is item 3.5"));
items.add(new Setting_ActivitySectionItem("Set Auto-silent"));
items.add(new Setting_ActivityEntryItem("Auto Silent", ""));
items.add(new Setting_ActivitySectionItem("Set Battery reminder"));
items.add(new Setting_ActivityEntryItem("Battery Reminder", ""));
adapter = new Setting_ActivityEntryAdapter(this, items);
adapter.notifyDataSetChanged();
setListAdapter(adapter);
我notifydatasetchange()
也在onResume
申请onRestart()
public void onRestart(){
super.onRestart();
System.out.println("onrestart");
try{
selectedParentMessage = ParentMessageListActivity.parentMsgSharedPref.getString("SelectedParentMessage", "None");
System.out.println("Selected Parent Message:"+selectedParentMessage);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
getListView().invalidateViews();
adapter.notifyDataSetChanged();
}
和同样的onPause()