如何在自动完成文本框中删除交叉签名

时间:2016-06-10 10:44:22

标签: android listview autocompletebox

如果写文字会自动删除,如果点击该十字,则所有文字都会从自动填充文字视图中移除,以及如何管理该十字标记的点击事件enter image description here

1 个答案:

答案 0 :(得分:1)

使用AutoCompleteTextView的android:drawableRight="@drawable/cross"属性。

要处理点击,您可以使用以下代码:

searchMultiAutoCompleteTextView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if(event.getAction() == MotionEvent.ACTION_UP) {
                if(event.getRawX() >= (searchMultiAutoCompleteTextView.getRight() - searchMultiAutoCompleteTextView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    // your action here

                 return true;
                }
            }
            return false;
        }
    });

希望它对您有用:)