How can I detect focused EditText in android?

前端 未结 8 1048
轮回少年
轮回少年 2020-12-05 06:24

I have a number of EditTexts in my page along with two buttons. I want the user to touch on any one EditText field and click any button to insert a

8条回答
  •  既然无缘
    2020-12-05 07:17

    This worked for me.

    e1 = (EditText) findViewById(R.id.editText1);
    
    e1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
       @Override
       public void onFocusChange(View arg0, boolean hasfocus) {
          if (hasfocus) {
             Log.e("TAG", "e1 focused") 
          } else {
             Log.e("TAG", "e1 not focused") 
          }            
       }
    });
    

提交回复
热议问题