Reputation: 3494
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 :-(.
Upvotes: 0
Views: 341
Reputation: 3337
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.
Now you can use this variable from within onBindView
, set your listener to the button's view there (view.findViewById(R.id.yourbuttonid)
).
Upvotes: 1