复选框preference额外的按钮? [英] CheckBoxPreference with additional Button?
问题描述
我想在复选框preference
显示额外的按钮。我已经通过继承管理这个复选框preference
键,自定义布局(使用的这个 code为基础)。不过,我奋斗到 OnClickListener
在我的 preferenceActivity
添加到该按钮。我已经尝试过使用一个全球性的 OnClickListener
-variable在扩展类复选框preference
以及添加 getView()
-method到 preferenceActivity
是应该返回preference的观点(以可以使用 findViewById(R.id.my_button)
,但是这两种方法不起作用: - (
I'd like to show an additional button in a CheckBoxPreference
. I've managed this by subclassing CheckBoxPreference
and a custom layout (using this code as a basis). However, I struggle to add an OnClickListener
to this button in my PreferenceActivity
. I've tried using a global OnClickListener
-variable in the class extending CheckBoxPreference
as well as adding a getView()
-method to the PreferenceActivity
that is supposed to return the Preference's view (to be able to use findViewById(R.id.my_button)
, but both approaches don't work :-(.
推荐答案
您复选框preference
的子类中创建的点击监听器的实例变量,它保存听者您希望设置。这个变量创建一个二传手,调用 notifyChanged()
设定值之后。这将导致 onBindView
被叫做监听器改变方法。
Create an instance variable for the click listener within your subclass of CheckBoxPreference
, which holds the listener you wish to set. Create a setter for this variable, calling notifyChanged()
after setting the value. This will cause the onBindView
method to be called on listener changes.
现在你可以使用这个变量从内部 onBindView
,你的监听器设置按钮的观点存在( view.findViewById(R.id.yourbuttonid )
)。
Now you can use this variable from within onBindView
, set your listener to the button's view there (view.findViewById(R.id.yourbuttonid)
).
这篇关于复选框preference额外的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!