I have a number of EditText
s 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
You can use View.OnFocusChangeListener
to detect if any view (edittext) gained or lost focus.
for (EditText view : editList){
view.setOnFocusChangeListener(focusListener);
}
....
private OnFocusChangeListener focusListener = new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
focusedView = v;
} else {
focusedView = null;
}
}
}
This goes in your activity or fragment or wherever you have the EditTexts. The ....
is just saying that you can put it anywhere else in the class. And obviously you would need to create an array with them in it, thus the editList
.
Simple Coding:
if(EditText1.isFocused()){
//EditText1 is focused
}else if(EditText2.isFocused()){
//EditText2 is focused
}