Android onxml中的onfocuschange [英] Android onfocuschange in xml
本文介绍了Android onxml中的onfocuschange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Android应用程序,在xml布局文件中,我有类似以下内容:
I have an Android app, and in the xml layout file I have something like this:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBoxDone"
android:checked="false"
android:clickable="true"
android:onClick="doneCheckBoxClicked" />
然后在我实现的Java代码中
Then in the java code I implemented
public void doneCheckBoxClicked(View v) { ...}
我可以使用类似的方法进行焦点更改操作吗?在xml中有类似
Can I use similar approach for focus changing actions. Have in the xml something like
android:onFocusChanged="editTextFieldFocusChanged"
,然后使用Java代码:
and then in java code:
public void editTextFieldFocusChanged(View v, boolean hasFocus) { ...}
还是没有办法在xml中执行onFocusChange?
Or there is no way to do onFocusChange in the xml?
推荐答案
我们无法在XML文件(如onclick侦听器)中设置editext的焦点更改侦听器.我们只需要在Java文件中完成该操作即可.
We can't set focus change listener of editext in xml file like onclick listener. We need to do it in Java file only.
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, 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();
}
}
});
这篇关于Android onxml中的onfocuschange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文