問(wèn)題描述
我的布局中有一個(gè) edittext
和一個(gè)按鈕,在我的代碼中我將 edittext
的 keyListener
設(shè)置為 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);
這樣我就無(wú)法輸入我的 edittext
.現(xiàn)在點(diǎn)擊我的按鈕,我應(yīng)該能夠輸入我的 ediitext
.我怎樣才能做到這一點(diǎn).這是一個(gè)簡(jiǎn)單的問(wèn)題,但我找不到任何解決方案.任何幫助將不勝感激.
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.
推薦答案
我現(xiàn)在可能遲到了,但是我就是這樣做的:
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);
}
}
基本上,在調(diào)用 setKeyListener(null)
之前,首先保存 EditText 的默認(rèn) KeyListener.然后,當(dāng)您單擊按鈕時(shí),再次調(diào)用 setKeyListener
,傳遞您之前保存的默認(rèn)偵聽(tīng)器.
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.
這篇關(guān)于編輯文本鍵偵聽(tīng)器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!