tags:

views:

31

answers:

1

Hi,

I am writing a custom preference with a seek bar, so far it works, except for one problem the ID of my seek bar is defined in XML, so when I try to use 2 of my custom prefernces and then I update the Seek Bar I cannot distinguish between the two.

SeekBar bar = (SeekBar)view.findViewById(R.id.PreferenceSeekBar);

Is there a way to generate a custom Resource ID at runtime? Or perhaps another way to solve this?

Thanks, Jason

+1  A: 

on the onBind ovverriden method of custom preference, you are passed a View view, which contains all the views on the current preference activity.

There is no onBind() method on Preference. There is an onBindView() method. However, the View passed to onBindView() is whatever View you returned from onCreateView(), or the View inflated from your specified layout file if you went that route. It is not the entire activity.

Make sure you are calling findViewById() on the widget that was created for your Preference, not something with broader scope.

Also, bear in mind that PreferenceActivity is a ListActivity. If your custom Preference scrolls off the screen, its View may be handed to another instance of your custom Preference for recycling.

CommonsWare
Yea, I know even considering that the affect I am getting is that both Seek Bars are moving when I move only one. Which doesn't make sense considering the View passed to me does not contain both of the seek bars
Jason
@Jason: This problem sounds really familiar, though I do not recall the solution.
CommonsWare
@CommonsWare: shame, I have been wracking at this for a while, if I create a copy of the custom prefernce class and use that - it solves it, suggesting a mixed reference but i cannot find any.
Jason