Ad
Requesting Focus To A EditText After Another EditText Has Been Touched?
I have 2 EditText
(myEditText1
and myEditText2
)
And I need when touch myEditText1
1. Do some business [No problem here and required business applied]
2. Then request focus to myEditText2
[ No luck? ]
final EditText myEditText1 = (EditText) findViewById(R.id.myEditText1);
final EditText myEditText2 = (EditText) findViewById(R.id.myEditText2);
// ...
myEditText1.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// My business when myEditText1 touched [ OK ]
// ...
// TODO
// Need to request focus to another EditText myEditText2 ?
return false;
}
});
I try some solutions like following trials
But no luck and focusing still on myEditText1
myEditText2.requestFocus();
Related questions
EditText request focus
Change Focus to EditText Android
Ad
Answer
You can set an OnClickListener
on your edit text like this:
this.editText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//your code
editText2.requestFocus();
}
});
Just take care about a special case
onClick() is not called when the EditText doesn't have focus
And you can find details of this case in the following question thread
onClick event is not triggering | Android
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad