2016-09-25 57 views
0

OnButtonClick監聽器我想禁用EditText進行編輯,然後再次打開它。禁用後啓用Edittext

下面兩行我殘疾的EditText

editTextWight.setEnabled(false); 
editTextWight.setFocusable(false); 

但是,當我嘗試打開它失敗。鍵盤無法打開。

editTextWight.setFocusable(true); 
editTextWight.setFocusableInTouchMode(true); 
editTextWight.setClickable(true); 
editTextWight.setEnabled(true); 

請幫我啓用EditText。

回答

0

禁用編輯文本使用

editTextWight.setEnabled(false); 
editTextWight.setInputType(InputType.TYPE_NULL); 
editTextWight.setFocusable(false); 

,使編輯文本使用

editTextWight.setEnabled(true); 
editTextWight.setInputType(InputType.TYPE_CLASS_TEXT); 
editTextWight.setFocusable(true); 
1

你可以試試這個兩塊爲我的項目的代碼運行線路:

editTextWight.setFocusable(true); 
editTextWight.setFocusableInTouchMode(true); 

我做這個例如afterTextChanged()被調用,因爲我必須先禁用這個EditText然後啓用它後來!

所以,只用上面的兩個方法調用,而不是所有四個。

祝你好運,讓我知道它是否工作!

1

謝謝Eenvincible和sajan。你的回答可以幫助我解決問題。我用這4種方法啓用了編輯窗口。

editTextWight.setEnabled(true); 
    editTextWight.setInputType(InputType.TYPE_CLASS_NUMBER); 
    editTextWight.setFocusable(true); 
    editTextWight.setFocusableInTouchMode(true);