我怎样才能知道什么时候的EditText失去焦点 [英] How can i know when a edittext lost focus

查看:116
本文介绍了我怎样才能知道什么时候的EditText失去焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要赶在一个EditText失去焦点,我已经在用户搜索的问题,但我没有找到任何答案。

I need to catch when an EditText loses focus, I've search in users questions but i didn't find any answer.

我用focuschangelistener这样

I use focuschangelistener like this

OnFocusChangeListener foco = new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        // TODO Auto-generated method stub

    }
};

但它并不适合我。

But it doesn't work for me

感谢

推荐答案

实施 onFocusChange setOnFocusChangeListener 中,有一个布尔参数hasFocus。如果这是假的,你已经失去焦点到另一个控件。

Implement onFocusChange of setOnFocusChangeListener and there's a boolean parameter for hasFocus. When this is false, you've lost focus to another control.

 EditText txtEdit = (EditText) findViewById(R.id.edittxt);

 txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {          

        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
               // code to execute when EditText loses focus
            }
        }
    });

这篇关于我怎样才能知道什么时候的EditText失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆