Update existing Preference-item in a PreferenceActivity upon returning from a (sub)PreferenceScreen

前端 未结 8 1787
清歌不尽
清歌不尽 2020-12-16 19:36

I have a PreferenceActivity with a bunch of (Sub)PreferenceScreens. Each such (Sub)PreferenceScreen represents an account and has the account-username as its title.

8条回答
  •  执念已碎
    2020-12-16 20:36

    I found a solution to this. I have a hierarchy like this, each of these is a PreferenceScreen:

    main settings
      -> users list
        -> user1 settings
        -> user2 settings
        ...
    

    In the users list, title of the sub-screen is dependent on the user settings. Now when I create the user list, I store the list adapter to a variable in my PreferenceActivity.

     PreferenceScreen usersListScreen = ...
     userScreenListAdapter = (BaseAdapter)usersListScreen.getRootAdapter();
    

    Now when userX-settings are edited, I set the titles in the usersListScreen and after that call:

    userScreenListAdapter.notifyDataSetChanged();
    

    which updates the list UI and the changes are visible.

提交回复
热议问题