0

我已经使用viewFlipper. 现在我想setWallpaper。但是当我按下setWallpaper按钮时,我的 coad 不工作。这是我的代码:

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;

}

 }
}
4

1 回答 1

0

编辑* - 您没有更新您的其他 int i,仅更新 onCreate() 中 for 循环内的一个。而不是gallery[i],它实际上应该是类似gallery[currentFlipperIndex]“currentFlipper”索引当然是您的视图翻转器的当前索引。

于 2012-09-03T02:45:48.650 回答