2013-06-21 15 views
8

Tercihim var android: layout gft. Düzeni, xml dosyasındaki tercihin android: layout özelliğine ayarladım.Özel düzen ile tercih görünümüne göz atın

Şimdi, düzende bir düğmenin başlatılması gerekiyor (bu bir +1 düğmesi). Bu düğmeyi onCreate yönteminde almam gerekiyor (bu bir +1 düğmesi), ancak findViewById(button_id) kullandığımda, null değerini döndürür.

Bu tercihin görünümünü elde etmenin bir yolu var mı?

UPDATE: Tercihi xml ekledikten sonra tercih oluşturulmuyor gibi görünüyor, bu yüzden boş olurum. FindViewById'i arayabileceğim yer bu yüzden düğme zaten oluşturuldu mu?

Teşekkürler.

Tercihler xml:

<Preference android:title="Rate this app" 
    android:key="rate" 
    android:widgetLayout="@layout/plusone_pref"/> 

</PreferenceScreen> 

Tercih düzeni xml: Daha sonra, Preference uzanan bir sınıf oluşturmak onBindView geçersiz kılmak gerekiyor ve erişebileceksiniz

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.gms.plus.PlusOneButton xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus" 
android:id="@+id/plus_one_button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:focusable="false" 
plus:size="standard" /> 

cevap

9

görünüm.

public class MyPreference extends Preference { 

    ... 

    @Override 
    protected void onBindView(View view) { 
     super.onBindView(view); 
     View myView = (View) view.findViewById(R.id.my_id); 
     // ... do stuff 
    } 

} 

Muhtemelen biraz daha yöntemleri geçersiz kılmak zorunda PreferenceActivity özel tercihi hakkında okuyacağız - http://developer.android.com/guide/topics/ui/settings.html

İlgili konular