ListView: TextView with LinkMovementMethod makes list item unclickable?

前端 未结 11 763
野的像风
野的像风 2020-11-29 17:33

What I want to do: A list with messages like this:

and here is the mnessage the user writes, that will wrap nicely to the next line.

11条回答
  •  野性不改
    2020-11-29 18:22

    This is happened because when we press on list item it sends the press event to all its children, so the child's setPressed calls rather than the list item. Hence for clicking the list item, you have to set the child's setPressed to false. For this, you have to make custom TextView class and override the desired method. Here is the sample code

    public class DontPressWithParentTextView extends TextView {

    public DontPressWithParentTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    @Override
    public void setPressed(boolean pressed) {
        // If the parent is pressed, do not set to pressed.
        if (pressed && ((View) getParent()).isPressed()) {
            return;
        }
        super.setPressed(pressed);
    }
    

    }

提交回复
热议问题