Skip to content Skip to sidebar Skip to footer

OnTouchListener In Adapter ListView Make OnItemClickListener Not Running

I creating custom adapter for my list view. In getView method, I set onTouchListener for LinearLayout in my custom adapter. For some reason, onItemClickListener in my listview can'

Solution 1:

you must return false to propagate the touch event so the click listener can capture the click event so:

   llBackground.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v.setBackground(view.getResources().getDrawable(R.drawable.border_clicked));
                break;
            case MotionEvent.ACTION_UP:
                v.setBackground(view.getResources().getDrawable(R.drawable.border));
                v.performClick();
                break;
            case MotionEvent.ACTION_CANCEL:
                v.setBackground(view.getResources().getDrawable(R.drawable.border));
                break;
            }
            return false;
        }
    });

Post a Comment for "OnTouchListener In Adapter ListView Make OnItemClickListener Not Running"