2016-06-10 38 views
0

如果寫的文字,它會自動刪除,如果點擊在十字架上的所有文本從自動填充文本視圖中刪除,以及如何奶源點擊叉號enter image description here如何將刪除自動完成文本交叉跡象

+0

你需要的是一個TextWatcher所以當用戶在文本字段中輸入字符,你可以看到。在這些方法,即:afterTextChanged->你必須編寫邏輯來顯示你的十字按鈕。 – cafebabe1991

回答

1

使用android:drawableRight="@drawable/cross"屬性的事件AutoCompleteTextView的。

要處理點擊就可以使用下面的代碼:

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; 
     } 
    }); 

希望它會爲你:)工作

+0

也想處理點擊我的片段...... –

+0

我已經添加了代碼來處理點擊十字按鈕。希望它能起作用。 :) – Neo

+0

thanx neo其工作酷 –