0

I am working on a Live Wallpaper. In this I want to have a background image selected by user and some other image rotating/Moving over the Background Image.

I want to show a list of 4-6 images through preferences, in which user can select one. I want to set user selected image in background.

How can I do that. Should I use ListPreference?

I read Choosing background for Live Wallpaper but could not get it work.

Thanks

Community
  • 1
  • 1

1 Answers1

0

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.

Community
  • 1
  • 1