problem accessing widget in Preference widgetLayout

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


Sponsored Links
 Hi,

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


My Preference XML is:

<PreferenceScreen
        xmlns:android=" http://schemas.android.com/apk/res/android" ;
        android:key="first_preferencescreen">

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


         <Preference    android:id="@+id/displayimageview"
                                        android:key="displayimagekey"
                        android:title="Display Image"
                        android:summary="Select Display Image"
                        android:widgetLayout="@layout/displayimage"
                         />

</PreferenceScreen>


My widget XML is:

        <LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                >

        <ImageButton android:id="@+id/displayimagebutton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="1dp"
                />

     </LinearLayout>


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");
          else
          {
                  ib = (ImageButton)v1.findViewById(R.id.displayimagebutton);
          }

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

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(R.id.displayimageview);
but that just returns null also.

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

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

Thanks!

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.

Thanks



>


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 <noah.belc...@gmail.com> 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 <godsm...@gmail.com> wrote:
> > >



Other Threads

1. low quality background in 1.1

Hi,
why does the background becomes low quality in the emulator?

thanks, COY.

-- 

2. Android Salip BlackBerry dan iPhone

Copas dari DetikInet:

Jakarta - Android berhasil menggeser posisi BlackBerry dan iPhone
sebagai ponsel paling laris terjual di Amerika Serikat selama kuartal
kedua 2010 lalu.

Demikian menurut laporan NPD Group (National Parts Depot). Posisi
Android terus merangsek naik ke posisi atas dengan perhitungan
sebanyak 33% ponsel yang dibeli pasar dari awal April hingga akhir
Juli.

{*filter*}tara BlackBerry besutan Research in Motion (RIM) terpaksa lengser
ke posisi kedua dengan total pangsa pasar penjualan 28%. iPhone
keluaran Apple harus puas bertengger di peringkat ketiga dengan total
penjualan 22%.

"{*filter*}tara sistem operasi yang dikembangkan Google merebut pangsa
pasar RIM, Apple mulai terlihat mendapatkan keuntungan dari iPhone 4
yang baru diluncurkannya," tandas Executive Director bagian Analis
NPD, Ross Rubin.

Seperti dikutip detikINET dari AFP, Jumat (6/8/2010), ponsel Android
paling populer adalah Motorola Droid, disusul HTC Droid Incredible dan
HTC Evo 4G. RIM sendiri berharap akan kembali meraih posisi puncak
dengan diluncurkannya smartphone Torch yang mengandalkan OS 6.

"BlackBerry OS 6 akan segera menawarkan fitur populer yang juga
diluncurkan pada handset Android, seperti dukungan kapasitif layar
sentuh dan browser berbasis WebKit," tukas Robin yang juga
menyayangkan layar Torch tidak memiliki daya tarik layaknya Android
maupun iPhone.

"Meskipun iPhone telah menjadi headline penjualan selama beberapa
tahun terakhir di pasar smartphone, sistem operasi Android justru
menunjukkan ekspansi paling signifikan diantara pelanggan saat ini,"
papar lembaga riset Nielsen ketika mengumumkan hasil pengamatannya.

-- 
"Indonesian Android Community [id-android]" 

Join:  http://www.***.com/ 
Moderator: id.andr...@gmail.com
ID Android Developer:  http://www.***.com/ 
ID Android Surabaya:  http://www.***.com/ 
ID Android on FB:  http://www.***.com/ 

3. Desire NexTSense Official Sense-FroYo 2.

4. Thanks, worked perfectly

5. HTML 5 Camera access

6. LVL returns LICENSED with anonymous accounts...

7. adding a splash screen to an APK