Moving the focus from One EditText to Another (Horizontal Direction) - Android
I have a Scrollview as a parent view, within that i have placed some mixture of linear layout and there is no probs in the design, but while testing the app, i found that there is a problem in movement of cursor, my intention is to move the focus from one edit text to another that is located adjecent(Horizontally), but when i click the enter button at the bottom, it moves the focus to the next edit text that is vertically located (I knoe,this is default one).
Even i tried with implementing the EditorAction, still the same issue exists.
This is the code that i used to move the focus from one edit text to another.
// Adding the special listener, to be invoked when the action is performed on the editor
firstEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if(actionId == EditorInfo.IME_ACTION_UNSPECIFIED || actionId == EditorInfo.IME_ACTION_NEXT) {
// Move the focus to the next edittext(secondEditText)
secondEditText.requestFocus();
}
return false;
}
});
Please let me know, how to move the focus from one text box to another placed in a horizontal direction. The above code moves the focus to text box that is vertically located. I tried with searching google a lot, but no results.
I have also shared that screen for better clarity.
Hope 开发者_JS百科i could get a better response here.
Thank you
public abstract void onFocusChange (View v, boolean hasFocus){
if(!hasFocus){
secondEditText.requestFocus();
}
}
but fails when scrolled up coz, even in that case the second EditText gets focus and not the above view..
a better solution could be,
GestureDetector.OnGestureListener lis = new GestureDetector.OnGestureListener(){
@Override
public boolean onDown(MotionEvent arg0) {
if(firstEditText.hasFocus){
secondEditText.requestFocus();
return true;
}
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
}
精彩评论