Focusable EditText in the ListView and onItemClick

前端 未结 3 1548
天涯浪人
天涯浪人 2020-12-15 08:27

In each ListView item I have EditText.

When I set android:focusable=\"false\" for EditText then onItemClick

3条回答
  •  情歌与酒
    2020-12-15 08:42

    My solution:

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        ViewHolder vh = (ViewHolder) view.getTag();
        //vh.row is the convertView in getView or you may call it the row item itself
        ((ViewGroup)vh.row).setDescendantFocusability(view instanceof EditText?ViewGroup.FOCUS_AFTER_DESCENDANTS:ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        return false;
    }
    

    And add

    android:descendantFocusability="blocksDescendants"
    

    to the view group in the layout xml file for the list row item.

提交回复
热议问题