Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check an EditText has focus?

How to check an EditText has focus? is there any method boolean hasFocus()

like image 897
Mohammed H Avatar asked Apr 23 '14 05:04

Mohammed H


1 Answers

Yes, hasFocus() is there, inherited from android.view.View

Another way to achieve this

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

if(this.getCurrentFocus().getId() == et.getId()){
    // your view is in focus
}else{
    // not in the focus
}
like image 64
Hashir Sheikh Avatar answered Oct 27 '22 00:10

Hashir Sheikh