在转盘中自动显示当前图像的位置

时间:2012-09-21 18:05:30

标签: android position carousel

在我的申请中,我有一个带图片的旋转木马。我想自动检测当前图像的位置,其中包含没有clickListener的祝酒词。

例如:当我滚动我的轮播时,我的位置为零,我想自动显示当前图像的位置。

我尝试过一切都没有成功。有什么想法吗?

我的代码:

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

    final Carousel carousel = (Carousel)findViewById(R.id.carousel);


    carousel.setOnItemSelectedListener(new OnItemSelectedListener(){ 

        public void onItemSelected(CarouselAdapter<?> parent, View view, 
               int position, long id) { 

            carousel.setCallbackDuringFling(false);   

            //final int[] ids = {R.drawable.bee, R.drawable.robot, R.drawable.adresse};      

            switch(position){ 
            case 0: 

                //view.setBackgroundResource(ids[0]); 

                Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_LONG).show();                               
                break; 
            case 1: 
                 //view.setBackgroundResource(ids[1]); 

                Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_LONG).show();
                break; 
            case 2: 

                Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
                break; 
            case 3: 

                 Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
                 break; 
            case 4: 

                 Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
                 break; 
            case 5: 

                 Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
                 break; 

            } 

        } 

       public void onNothingSelected(CarouselAdapter<?> parent) { 

       } 

    } 
    ); 


    carousel.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(CarouselAdapter<?> parent, View view,
                int position, long id) {                

            switch(position){ 
            case 0: 
                Intent myIntent1 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent1);
                break;
            case 1: 
                Intent myIntent2 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent2);
                break;
            case 2: 
                Intent myIntent3 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent3);
                break;
            case 3: 
                Intent myIntent4 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent4);
                break;
            case 4: 
                Intent myIntent5 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent5);
                break;
            case 5: 
                Intent myIntent6 = new Intent(MainActivity.this, Onglet1.class); 
                MainActivity.this.startActivity(myIntent6);
                break;
            } 


        } 

    });  
}

}

0 个答案:

没有答案