2

我正在开发一个应用程序,并且我在一个屏幕中有一个列表视图,因为我正在使用类传递值。在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()

4

4 回答 4

2

解决了

@Override
    public void onResume(){
    super.onResume();
        adapter.clear();
        addItem();
    }

addItem()是将列表项添加到类并生成适配器并设置列表视图的函数。

于 2013-02-15T10:46:17.647 回答
1

如何使用您在适配器中使用的相同变量创建适配器的新实例并再次将适配器设置在列表中。

在 onResume 上试试这个:

adapter = new Setting_ActivityEntryAdapter(this, items);
setListAdapter(adapter);
于 2013-02-14T07:27:43.077 回答
0

称它为yourlistView.invalidateViews();

试试这个 。

ListAdapter la = listView.getAdapter();
                        if( la != null){
                            ((BaseAdapter)la).notifyDataSetChanged();


                }
于 2013-02-14T06:58:02.053 回答
0

为你notifydatasetchange()的适配器做listviewinonStart()

于 2013-02-14T07:00:33.790 回答