EditText失去焦点

4

在自定义 ListView 中,有两列,一列包含 TextView 组件,另一列包含 EditText 组件。当用户点击 EditText 时,为了输入一些偏好设置,软键盘会进入焦点,但 EditText 的焦点会丢失。我该如何解决这个问题?

2个回答


4

对于 editText,请使用 setFocusable(false) 方法。对于 textView,请使用 setFocusable(true) 方法。

同时,为 textView 和 editText 编写失去焦点的监听器:

textView.setOnFocusChangeListener(new OnFocusChangeListener() {          

    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus)
        {
           //do job here when EditText loses focus
        }
    }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接