0

我想从 viewpager 设置壁纸(选定的图像,壁纸按钮)。我有不同的图片(R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4,R.drawable.a5,R.drawable.a6 ...... ..)我的问题,id没有改变(总是相同的图片,R.drawable.a1)问题出在哪里?, 谢谢

应用程序类;

public class App extends Activity  implements OnPageChangeListener {
protected static final Context Context = null;

private Integer[] ListOfID = {
        R.drawable.a1, R.drawable.a2, R.drawable.a3, R.drawable.a4, R.drawable.a5,     R.drawable.a6, R.drawable.a7,
        R.drawable.a8, R.drawable.a9, R.drawable.a10, R.drawable.a11, R.drawable.a12, R.drawable.a13, R.drawable.a14, R.drawable.a15,
        R.drawable.a16, R.drawable.a17, R.drawable.a18, R.drawable.a19, R.drawable.a20};
private static final int count = 22;

View view=null;
Integer imageId;
final Activity act = this;  
private int indexOfImage = 0;
    public LinearLayout layout;

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

     MyPagerAdapter adapter = new MyPagerAdapter();
       final ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
         myPager.setAdapter(adapter);
         myPager.setCurrentItem(12); 
         myPager.setOnPageChangeListener(this);

         Button next = (Button) findViewById(R.id.buttonnext);
         next.setOnClickListener(new View.OnClickListener(){

             public void onClick(View v) {
                 myPager.setCurrentItem(myPager.getCurrentItem()+1);
             }
         }); 

         Button previous = (Button) findViewById(R.id.buttonprevious);
         previous.setOnClickListener(new View.OnClickListener(){

             public void onClick(View v) {
                 myPager.setCurrentItem(myPager.getCurrentItem()-1);
             }
         }); 

         Button duvarbtn = (Button) findViewById(R.id.button1);
         duvarbtn.setOnClickListener(new View.OnClickListener(){
            int id=ListOfID[indexOfImage];
             public void onClick(View v) {

                WallpaperManager myWallpaperManager
                 = WallpaperManager.getInstance(getApplicationContext());
                try {                                                                      
                    myWallpaperManager.setResource(id);                       
                } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                }
             }          
         }); 
}

public void onPageScrollStateChanged(int arg0) {
    // TODO Auto-generated method stub

}

public void onPageScrolled(int position, float arg1, int arg2) {
    // TODO Auto-generated method stub

        }

public void onPageSelected(int position) {
    // TODO Auto-generated method stub

    indexOfImage = position;
    switch (position) {
    case 0:
   firstpage(position);       
        break;

    case 21:
        firstpage(position);
        break;
    }

}

public void firstpage(int position) {
    // TODO Auto-generated method stub
    ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
     int pageCount = getCount();
     if (position == 0){
         //
         myPager.setCurrentItem(pageCount-2,false);
     } else if (position == pageCount-1){
        //ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
         myPager.setCurrentItem(1,false);
     }
}


private int getCount() {
    // TODO Auto-generated method stub
     return count;
}
public void onClick(View v) {
    // TODO Auto-generated method stub
    //Filter f = (Filter) v.getTag();
   // MyPagerAdapter.show(this, input, f);
}
 public void onDestroy()
    {
     super.onDestroy();
    }   
}
4

0 回答 0