[英]How to automatically press enter key when edittext is not null?
I'm make a EditText and the value i got from Firebase, it is possible if edittext is not null then enter key pressed automatically 我创建一个EditText并从Firebase获取值,如果edittext不为null,则可能会自动输入按下的键
private void init(){
Log.d(TAG, "init: initializing");
if (mSearchText != null){
what must i write here?
}
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_DONE
|| keyEvent.getAction() == KeyEvent.ACTION_DOWN
|| keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){
//execute our method for searching
geoLocate();
}
return false;
}
});
[1] you can try below code [1]您可以尝试以下代码
String yourtext=mSearchText.getText().toString().trim();
if(!TextUtils.isEmpty(yourtext)) //or else you can use if(yourtext!=null && !yourtext.equalsIgnoreCase(""))
{
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_DONE
|| keyEvent.getAction() == KeyEvent.ACTION_DOWN
|| keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){
//execute your method for searching
geoLocate();
}
return false;
}
});
}
[2] else you can achieve your functionality using this(Direct method calling) [2]否则您可以使用this(直接方法调用)来实现您的功能
String yourtext=mSearchText.getText().toString().trim();
if(!TextUtils.isEmpty(yourtext)) //or else you can use if(yourtext!=null && !yourtext.equalsIgnoreCase(""))
{
//execute your method for searching
geoLocate();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.