简体   繁体   中英

GridView after scroll the ACTION_UP onTouchListener to the child wont call

//child view of GridView in getView() method. Seems that need to implement custom GridView that will handle the whole scroll and other touch operations on his child. Thanks for any help.

class ViewHolder implements View.OnTouchListener {
    ImageView image;
    TextView text;
    int position;
    RelativeLayout root;

    public ViewHolder(View v, int position) {
        this.image = (ImageView) v.findViewById(R.id.grid_image);
        this.text = (TextView) v.findViewById(R.id.item_text);
        this.root = (RelativeLayout) v.findViewById(R.id.root_layout);
        this.position = position;
        image.setOnTouchListener(this);

    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {

        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                Log.e("DOWN", "YES");
                return true;
            case MotionEvent.ACTION_MOVE:

                break;
            case MotionEvent.ACTION_UP:
                Log.e("UP", "YES");
                break;
        }
        return true;
    }


}

That's because when you scroll, the touch events are rerouted to the grid view. When that happens, you'll see an ACTION_CANCEL. You need to account for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM