简体   繁体   中英

Android - Click through a TextView when not long-pressing (selecting) the TextView

What I'm trying to achieve is have a TextView inside of a CardView (that's in a RecyclerView) be selectable only when you long-press the TextView. And if you don't long-press the TextView, it is ignored and the input (click) is passed on to the parent (CardView) which has it's own event to do when pressed.

I've tried one solution where I add a "OnLongClickListener" to the TextView and enable "selectable" when triggered. However when you short-press the TextView, it blocks the input from reaching the parent CardView, which prevents the CardView from performing it's action, which is expanding the CardView.

textView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            textView.setTextIsSelectable(true);
            return true;
        }
    });

I'm trying to find a solution to have the TextView be essentially ignored and pass the input to it's parent when it isn't long-pressed. Anyone have any ideas on how to achieve this?

I've looked here already: TextView selectable just on long click

Just write textView.setTextIsSelectable(true);

Remove onLongClick event, When you long press on Textview then it auto select textview text

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