在运行时Generte资源ID? [英] Generte resource ID at runtime?
问题描述
我写一个自定义的preference有搜索栏,到目前为止,它的工作原理,但有一个问题,我的搜索栏的ID被定义在XML中,所以当我尝试使用我的自定义$ P $ 2 pfernces然后我更新搜索栏,我不能区分这两个。
搜索栏栏=(搜索栏)view.findViewById(R.id. preferenceSeekBar);
有没有办法在运行时生成自定义资源ID?
或者另一种方式来解决这个问题?
谢谢,
杰森
在自定义preference的onBind ovverriden方法,你传递一个View视图,其中包含对当前preference活动各方面的意见。
块引用>有没有
onBind()
在preference
方法。有是的一个onBindView()
方法。但是,查看
传递给onBindView()
是什么查看
从onCreateView返回()
,或者从您指定的布局文件膨胀,如果你去这条路线的查看
。它不是整个活动请确保您所呼叫
findViewById()
上是为创建的小部件的preference
,不是与范围更广。另外,请记住,
preferenceActivity
是ListActivity
。如果您的自定义preference
关闭屏幕滚动,其查看
可以切换到自定义的另一个实例preference
进行回收。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
解决方案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 onPreference
. There is anonBindView()
method. However, theView
passed toonBindView()
is whateverView
you returned fromonCreateView()
, or theView
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 yourPreference
, not something with broader scope.Also, bear in mind that
PreferenceActivity
is aListActivity
. If your customPreference
scrolls off the screen, itsView
may be handed to another instance of your customPreference
for recycling.这篇关于在运行时Generte资源ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!