0

I have make a simple app using viewFlipper. now I want to setWallpaper. but my coad is not working when I press setWallpaper button. Here is my code:

public class WallpaperChooserActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */

ViewFlipper vp;
Bitmap bmp;
ImageView image;
int i;
int galleryId [] ={R.drawable.bela1,R.drawable.bela2,R.drawable.bela3,
        R.drawable.bela4,R.drawable.bela5};


private void setFlipperImage1(int res) {
       // Log.i("Set Filpper Called", res+"");
        image = new ImageView(getApplicationContext());
        image.setImageResource(res);
        vp.addView(image);
}  



public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initilizeVariable();   

    for(int i=0;i<galleryId.length;i++)
    {
        setFlipperImage1(galleryId[i]);
    }



}

private void initilizeVariable() {
    // TODO Auto-generated method stub

    vp =(ViewFlipper)findViewById(R.id.ViewFlipper01);
    Button setWall = (Button)findViewById(R.id.btnSetWall);
     Button moreApp = (Button) findViewById(R.id.btnMore);
     Button share = (Button) findViewById(R.id.btnShare);
     Button rate = (Button)findViewById(R.id.btnRate);
     ImageButton next = (ImageButton)findViewById(R.id.ibNext);
     ImageButton prev = (ImageButton)findViewById(R.id.ibPrev);

     setWall.setOnClickListener(this);
    moreApp.setOnClickListener(this);
    share.setOnClickListener(this);
    rate.setOnClickListener(this);
    next.setOnClickListener(this);
    prev.setOnClickListener(this);

}


public void onClick(View v) {
    // TODO Auto-generated method stub

 switch (v.getId()){

    case R.id.ibNext:

        vp.showNext();
    break;

    case R.id.ibPrev:

        vp.showPrevious();
        break;

    case R.id.btnSetWall:

        //Bitmap wallpaper = BitmapFactory.decodeStream(getResources().openRawResource(galleryId [i]));
        WallpaperManager myWallpaperManager  = WallpaperManager.getInstance(getApplicationContext()); 

         try {

                 myWallpaperManager.setResource(galleryId [i]);


         } catch (IOException e) {
                 // TODO Auto-generated catch block
              e.printStackTrace();
         }break;

}

 }
}
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
xoticjerk
  • 3
  • 1

1 Answers1

0

Edit*- You are not updating your other int i, only the one inside the for loop in your onCreate(). Instead of gallery[i] it should really be something like gallery[currentFlipperIndex] "currentFlipper" index of course being the current index of your view flipper.

Jade Byfield
  • 4,668
  • 5
  • 30
  • 41
  • Yes i also use user permission in my manifest .....but the code is not working. i thing the problem is here : myWallpaperManager.setResource(galleryId [i]); please check it. – xoticjerk Sep 03 '12 at 09:53
  • I've edited my original answer. Let me know if it works out for you buddy – Jade Byfield Sep 03 '12 at 18:09
  • hey Jade Byfield, thanks for new answer but it's not working.i notice something that when i use gallary[4] in case of.... InputStream stream = getResources().openRawResource(galleryId[i]); then it is working but it makes for a single wallpaper.but i need current image in the viewFilpper for setting wallpaper. – xoticjerk Sep 04 '12 at 16:10
  • Hey. I tried edition my previous answer, let me know if this works. – Jade Byfield Sep 04 '12 at 23:16