She*_*lar 134 networking events android
任何人都可以建议我任何与焦点有关的事件EditText吗?我的应用程序包含一个EditText,它接受一个URL.
现在我的问题是,用户将在字段中输入URL并进一步移动,没有任何点击事件,即当焦点将从中移动时EditText,它应检测输入的Url并转到服务器.
如果我使用Json Parsing得到答复,那么它会更方便.
Pra*_*tik 492
这是焦点听众的例子.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
Toast.makeText(getApplicationContext(), "Got the focus", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Lost the focus", Toast.LENGTH_LONG).show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
Waj*_*han 11
在类顶部声明EditText的对象:
EditText myEditText;
Run Code Online (Sandbox Code Playgroud)在onCreate函数中找到EditText,在EditText中找到setOnFocusChangeListener:
myEditText = findViewById(R.id.yourEditTextNameInxml);
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus) {
Toast.makeText(this, "Focus Lose", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, "Get Focus", Toast.LENGTH_SHORT).show();
}
}
});
Run Code Online (Sandbox Code Playgroud)它工作正常.
小智 6
在kotlin中时,它将如下所示:
editText.setOnFocusChangeListener { view, hasFocus ->
if (hasFocus) toast("focused") else toast("focuse lose")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
145249 次 |
| 最近记录: |