問題描述
我有一個(gè) EditText.當(dāng)我點(diǎn)擊它時(shí),它變得可聚焦.我將鍵入要輸入到 EditText 中的輸入文本.我想為 EditText 實(shí)現(xiàn)一個(gè)監(jiān)聽器,這樣當(dāng)我停止輸入時(shí),它應(yīng)該自動(dòng)將該文本保存到數(shù)據(jù)庫中,而不是有一個(gè)按鈕.如何讓 EditText 的監(jiān)聽器來監(jiān)聽輸入是否停止?
I have an EditText. When i click on it, it becomes focusable. I will type the input text to be entered into the EditText. I want to implement a listener for EditText, so that when i stop typing, it should automatically save that text into the database instead of having a button. How to have a listener for EditText to listen that typing is stopped or not?
推薦答案
set edittext imeOption
set edittext imeOption
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
通過使用這樣的東西,
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// Specify your database function here.
return true;
}
return false;
}
});
或者,您可以使用 OnEditorActionListener
接口來避免匿名內(nèi)部類.
Alternatively, you can use the OnEditorActionListener
interface to avoid the anonymous inner class.
這篇關(guān)于為 EditText 實(shí)現(xiàn)文本觀察器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!