problem accessing widget in Preference widgetLayout

by hacksoft » Sun, 18 Apr 2010 13:28:03 GMT

Sponsored Links

I can't seem to get a handle to the embedded widget (via widgetLayout)
in my preference.

My Preference XML is:

        xmlns:android="" ;

                <EditTextPreference android:key="displayname"
                                                android:title="Display Name"
                                                android:summary="Choose a 
display name" />

         <Preference    android:id="@+id/displayimageview"
                        android:title="Display Image"
                        android:summary="Select Display Image"


My widget XML is:

        <LinearLayout xmlns:android=" 

        <ImageButton android:id="@+id/displayimagebutton"


I'm trying to get a handle on the displayimagebutton to embed an
ImageButton in a preference row.

My java code is:
          View v1 = null;
          v1 = findViewById(R.layout.preferences);
          ImageButton ib = null;
          if (v1 == null)
                  Log.d(SUBSYSTEM_TAG, "v1 = null");
                  ib = (ImageButton)v1.findViewById(;

I can't seem to get a view to the preferences I setup in
preferences.xml.  in my OnCreate() I'm calling:

and this seems to work fine since the preferences layout is
represented on the screen.  However I can't get a View to this layout
as my java code is trying above, so I can find the embedded widget.

I've tried: v1 = findViewById(;
but that just returns null also.

Any ideas on how I can get the ImageButton reference to my

I'm really disappointed on the lack of an Android example for this.


John Roberts


problem accessing widget in Preference widgetLayout

by Noah » Wed, 02 Jun 2010 07:24:42 GMT

 Did you ever get this resolved? I'm having the same problem.



Sponsored Links

problem accessing widget in Preference widgetLayout

by GodsMoon » Wed, 14 Jul 2010 21:34:38 GMT

  think you need to do findPreference instead of findViewById.
so like:
ib = (Preference) findPreference("displayimagekey");

Hope that helps.

On Jun 1, 3:20pm, Noah <> wrote:
> >

problem accessing widget in Preference widgetLayout

by AlanLawrence » Thu, 15 Jul 2010 16:45:38 GMT

 indPreference finds the Preference, findViewById is what you want to
get the button/widget...

however, it seems (I had a similar problem) that the widget isn't
being created at the time you addPreferences in your onCreate method,
only later; presumably if you wrote a custom Preference subclass,
you'd be able to grab the widget just as it was loaded by overriding
onBindView, or some other method; or you could write a custom widget
class that performs any load-time action you need in
onFinishInflate(!). However, if you can wait until the preference is
clicked, an easier option is to use an OnPreferenceClickListener, at
which point the same findViewById call does work...!

HTH, Alan

On Jul 14, 2:34pm, GodsMoon <> wrote:
> > >

Other Threads

1. where do control id's get defined.

I know that strings should be stored in res/strings.xml but where do i
store control names(ID's)?

In this example the name of the id variable(im guessing that's what
it's called) is list_item_title. Where would i define that value?

Also is this the only way to name controls? in most other languages
that I have used you ussually just set id="somestringvalue".



2. XMLHttpRequest Handling

Hi All,

I would like to know how do I handle XMLHttpRequest from javascript.

I have a WebView control in which I load the html file.
This html file onload calls a javascript function  onLoad().
This onLoad() calls a javascipt function in test.js file named getImage
This getImage() in javascript file has a xmlhttprequest call.

Both the test.html and test.js file are in the asset dir of the app.

Please let me know any configuration I have to make to give a AJAX

The same files if i host on a server and call in the webview Contol it
will call the ajax request and load the image.

waiting for suggestions.
Thanks in Advance.


3. buggy Android phone (Tmobile g1)

4. Zoom problem in OpenGL

5. unable to see # in webview

6. images sent via text

7. getSharedPreferences