How to add a button to PreferenceScreen
worked for me.
At the places of button I Used TextView and Added ImageView.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/background1"
android:layout_weight="1"
android:onClick="imageClicked1"/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/background2"
android:layout_weight="1"
android:onClick="imageClicked2"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView3"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/background3"
android:layout_weight="1"
android:onClick="imageClicked3"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_weight="1"
android:onClick="imageClicked4"
android:src="@drawable/background4" />
</LinearLayout>
<ListView android:id="@android:id/list"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
And Implemented the method for onClick events
for Eg for the first imageView
public void imageClicked1(View V)
{
Toast.makeText(this, "Image Clciked 1", Toast.LENGTH_LONG).show();
shfEditorObject.putInt("IMAGE", 1);
shfEditorObject.commit();
}
then fetched the image from sharedpreference and set as background.