Android how can i implement two on click on my ima

2019-08-04 08:39发布

问题:

I have a slider images in my app,can it is possible to put on my imageview 2 onclick functions at a time, for example:

1- if i click on image slider it's open another activity and my images are display.

2- if i swipe my image slider with finger swipe right and left.

3- i have complete the above 2points,but the problem is that just my swipe functionality works,my point num 1 is not working.

this is my code when i click on my slider image and open another activity and my images are display:

advertIV = (ImageView) findViewById(R.id.AdvertIV);
    advertIV.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(SearchResultDescription.this,ImageSwitcher.class);
            intent.putExtra("imageurls", imageurls);
            intent.putExtra("From", "Search");
            intent.putExtra("MakeName", MakeName);
            intent.putExtra("ModelName", ModelName);
            intent.putExtra("VariantName", VariantName);
            intent.putExtra("StockNumber", StockNumber);
            Log.d("CMH", "images url = " + imageurls);
            startActivity(intent);
        }
    });

and this is my swipe functionality code where i can move my images with fingers swipe:

advertIV.setOnTouchListener(new OnSwipeTouchListener() {
        public void onSwipeTop() {
            // Toast.makeText(ImageSwitcher.this, "top",
            // Toast.LENGTH_SHORT).show();
        }

        public void onSwipeRight() {

            // TODO Auto-generated method stub
            imageIndex--;
            //int maxsize=imageurls.size();
            if(imageIndex>=0){

            if(imageIndex==0){
                setbackground(imageurls.get(imageIndex), imageIndex);
            }else{
                setbackground(imageurls.get(imageIndex), imageIndex);
            }

            }else{
                imageIndex=0;
            }

            for (int i = 0; i < imageurls.size(); i++) {
                mDotsLayout[i].setBackgroundResource(R.drawable.grey_dot);
            }

            mDotsLayout[imageIndex].setBackgroundResource(R.drawable.red_dot);


        }

        public void onSwipeLeft() {

            // TODO Auto-generated method stub
            imageIndex++;
            int maxsize=imageurls.size();
            if(imageIndex<maxsize){

            if(imageIndex==maxsize-1){
                setbackground(imageurls.get(imageIndex), imageIndex);
            }else{
                setbackground(imageurls.get(imageIndex), imageIndex);
            }

            }else{
                imageIndex=maxsize-1;
            }

            for (int i = 0; i < imageurls.size(); i++) {
                mDotsLayout[i].setBackgroundResource(R.drawable.grey_dot);
           }

            mDotsLayout[imageIndex].setBackgroundResource(R.drawable.red_dot);




        }

        public void onSwipeBottom() {
            // Toast.makeText(ImageSwitcher.this, "bottom",
            // Toast.LENGTH_SHORT).show();
        }
    });

This is my slider image screen shot: