开发者

Generte resource ID at runtime?

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.fin开发者_开发知识库dViewById(R.id.PreferenceSeekBar);

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

Thanks, Jason


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.


For the benefit future comers:

Tag your view with setTag() and reference it baack with findViewWithTag();

source: Inflate a TableRow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜