Question

I would like to have a ListPreference where the user can choose between three kinds of organization (by topic, type or origin) and then, depending on his/her selection, a MultiSelectListPreference would be displayed to allow him/her to choose the set of tags for that previous selection that narrow down the events that he/she will see in the app.

ListPrefence (organized by...):

  • Topic
  • Type
  • Origin

MultiSelectListPreference for Topic:

  • Art
  • Entertainment
  • ...

MultiSelectListPreference for Type:

  • Movies
  • Parties
  • Exhibition
  • ...

MultiSelectListPreference for Origin:

  • Fb
  • Google
  • Blogs
  • ...

Any ideas how I could do that? Right now, in my onSharedPreferencesChanged I have the following:

else if (key.equals("possible_organizations_list")){
     System.out.println("key possible_organizations_list changed");
     String kindOfOrganization = sharedPreferences.getString(key, "By Type");
     if(kindOfOrganization.equals("By Type")){
           System.out.println("Selected By Type");
     }else if(kindOfOrganization.equals("By Topic")){
           System.out.println("Selected By Topic");
     }else if(kindOfOrganization.equals("By Origin")){
           System.out.println("Selected By Origin");
     }
}

but I'm not sure how can I connect this to the MultiSelectListPreference that I want to have.

Edit: I think it's worth mentioning, that my implementation does not need to have necessarily a ListPreference and a MultiSelectListPreference, is just what I thought could fit best, but any other suggestions will be also welcome.

Was it helpful?

Solution

I found a way but did not behave as I wanted it, so I implemented it different. Still, just in case someone is interested, I'm posting the solution that I found.

I created another preference's xml, activity and fragment and called them inside the main preferences when the ListPrefence changed. The problem with this approach is that, then you can access the multilists only when the list changes. I'm sure it could be "hacked" somehow but still, that made me think that it was not a good idea to make the user go through that first list to access the different multilists.

In the end, I just put the three multilists directly in the main preferences and enable/disable the active/non active following this approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top