2012/7/24 billb <[email protected]>

> Thanks for digging a bit deeper.
>
> I copied what you did and indeed got the click handled!
>
> The difference was that my subclass then referred to another layout xml
> file that actually showed a button as in this discussion (
> http://stackoverflow.com/questions/5298370/how-to-add-a-button-to-a-preferencescreen-android
> ).
>
> I stepped back to what you did and got the same results.
>

Ok, good, so I'm not insane :)


> I think the next step is to subclass the button and handle it the way you
> suggested for subclassing Preference.
>

You don't need to subclass Button.

A preference screen uses a list view, which creates views for items
(Preference and its subclasses) on an as needed basis.

The method that does that is actually defined in Preference, and you can
override it like this

protected View onCreateView(ViewGroup parent) {
 View view = super.onCreateView(parent);
 Button button = view.findViewById(R.id.my_preference_button);
  button.setOnClickListener(.... );
}

What this does is lets the base class inflate the item's layout, according
to what's defined in the XML, and then looks for the button in the inflated
view hierarchy.

However, if this was my app, I'd keep it as a clickable preference without
the button, so it looks more consistent with other, system-defined,
preferences -- perhaps adding a subtitle (the Android preference system
calls it "summary") saying something like "Tap to reset the password
cache", etc.


>
> As for my comments, my Russian is rusty, however, I am very pleased with
> the developer community and have found some very helpful people such as
> yourself.  I'm just surprised that it has been so difficult to find
> information on how to create the "new", "modern" style preference screen.
> Without people such as yourself, it would not be possible at all.   At
> least for mortals such as myself.
>

Oh, I don't post much these days at all. There are people here who do much
much more, and do it consistently.

-- K

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to