0

I am trying to show list of images in Preference, i can make it using ListPreference but want to show without Dialog.

I tried the link, but getting ClassCastException.

It should work dynamically else i can customize each preference and add it, but that would be poor.

Please see the attached sample image.

Any Help/Suggestion would be highly appreciable.

Sample Image

Updated.

I can create each custom Preference class to show images, but as i have 5 images need to be created different classes. See the Output attached image. Is there any alternate way to make it dynamically instead of static way?

Output Image

Community
  • 1
  • 1
moDev
  • 5,248
  • 4
  • 33
  • 63

1 Answers1

1

I havent tried this, but I would build everything in code then. so try to put this code in a for() statement in the preference class:

LinearLayout layout = new LinearLayout(this);
layout.setBackgroundResource(R.drawable.background1);
layout.setId(567890);

PreferenceScreen preference;
preference = getPreferenceScreen();
Preference new_preference = new Preference(this);
new_preference.setKey("key1");
new_preference.setTitle("");
new_preference.setLayoutResource(567890);
preference.addPreference(new_preference);
laplasz
  • 3,359
  • 1
  • 29
  • 40
  • How can i change image for each preference?? – moDev Feb 25 '13 at 08:06
  • each preference would use diff layout. each layout would contain diff background – laplasz Feb 25 '13 at 08:53
  • Isn't there any better solution to this?? How can i reference images and change on click of preference? isn't that possible? – moDev Feb 25 '13 at 08:55
  • so you want to change the bg of 1 preference by clicking on it? you havent mentioned this – laplasz Feb 25 '13 at 09:10
  • If i have to create different layout for each preference, then how it works dynamically?? if this can be answered, then rest can be done.. – moDev Feb 25 '13 at 09:12
  • when you create the custom layout for your custom preference use some iterator in the name of the bg image: `layout.setBackgroundResource(R.drawable.background+i); layout.setId(567890+i);` – laplasz Feb 25 '13 at 09:25
  • Getting resource not found exception on Id – moDev Feb 25 '13 at 10:07