Mohammed H
Mohammed H

Reputation: 7048

How to check an EditText has focus?

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

Upvotes: 6

Views: 10798

Answers (1)

Hashir Sheikh
Hashir Sheikh

Reputation: 1821

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
}

Upvotes: 12

Related Questions