I have a preference android: layout gft. I set the layout in the android: layout property of preference in the xml file.
Now I need to initialize the button in the layout (this is the +1 button). I need to get this button in the onCreate method (this is the +1 button), but when I use findViewById(button_id) , it returns null.
Is there any way to get an idea of this preference?
UPDATE: It seems that preference is not created after I add xml and I get null. Where can I call findViewById so that the button is already created?
Thanks.
Xml preferences:
<Preference android:title="Rate this app" android:key="rate" android:widgetLayout="@layout/plusone_pref"/> </PreferenceScreen>
Preferred xml layout:
<?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" />
android android-preferences
Ran
source share