1

在我的应用程序中,我有一个带有图片的轮播。我想自动检测没有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;
            } 


        } 

    });  
}

}
4

0 回答 0