問題描述
我的布局中有一個 edittext
和一個按鈕,在我的代碼中我將 edittext
的 keyListener
設置為 null
I have an edittext
and a button in my layout and in my code I'm setting keyListener
of the edittext
as null
editText.setKeyListener(null);
這樣我就無法輸入我的 edittext
.現在點擊我的按鈕,我應該能夠輸入我的 ediitext
.我怎樣才能做到這一點.這是一個簡單的問題,但我找不到任何解決方案.任何幫助將不勝感激.
so that I cannot type into my edittext
. Now on my button click I should be able to type into my ediitext
. How can I do that. It's a simple problem, but I'm not able to find any solution. Any help would be much appreciated.
推薦答案
我現在可能遲到了,但是我就是這樣做的:
I'm probably late now but, this is the way I do it:
public class MyActivity extends Activity
{
private KeyListener listener;
private EditText editText;
public void onCreate(...)
{
editText = ... // Get EditText from somewhere
listener = editText.getKeyListener(); // Save the default KeyListener!!!
editText.setKeyListener(null); // Disable input
}
// When you click your button, restore the default KeyListener
public void buttonClickHandler(...)
{
editText.setKeyListener(listener);
}
}
基本上,在調用 setKeyListener(null)
之前,首先保存 EditText 的默認 KeyListener.然后,當您單擊按鈕時,再次調用 setKeyListener
,傳遞您之前保存的默認偵聽器.
Basically, you first save the EditText's default KeyListener before you call setKeyListener(null)
. Then, when you click your button, you call setKeyListener
again, passing the default listener you previously saved.
這篇關于編輯文本鍵偵聽器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!