Unable to select the right button in a ListView with FastScroll enabled

I have a ListView with an image on the left, a title and subtitles in the center, and an ImageButton on the right (this button has no field on the right).

enter image description here

<ListView
    android:id="@+id/contacts"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:cacheColorHint="@android:color/transparent"
    android:fastScrollEnabled="true"
    android:scrollbarStyle="outsideInset"/>

I have included quick scrolling for this ListView. When I try to right-click the ImageButton, the scroll bar is in focus and the ListView starts scrolling. I can not select the button on the right. Please help me.

+4
source share
1 answer

You need to redefine the class ListViewand its method onInterceptTouchEvent.

public class CustomListView extends ListView {
    public CustomListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        setFastScrollEnabled(false);
        boolean possibleResult = super.onInterceptTouchEvent(ev);
        setFastScrollEnabled(true);

        boolean actualResult = super.onInterceptTouchEvent(ev);

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            return possibleResult && actualResult;
        }

        return super.onInterceptTouchEvent(ev);
    }
}

And it will look like this:
enter image description here

, , - .
.

Google PhoneBook, :
enter image description here
, , 100% .

,

+3

Source: https://habr.com/ru/post/1625950/


All Articles