EditText´s android:nextFocusDown attibute stops working when onClick is set

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 17:04:23

Do it programmatically because when you call android:nextFocusDown in XML may be the object that you want to call in the nextFocus will not create it till.

private void setUpView(){
    editText1=(EditText)findViewById(R.id.editText1);
    editText2=(EditText)findViewById(R.id.editText2);
    editText3=(EditText)findViewById(R.id.editText3);
 }
private void setUpFocus(){
  editText1.setNextFocusDownId(R.id.editText2);
    editText2.setNextFocusDownId(R.id.editText8);// you can give focus to any id
    editText3.setNextFocusDownId(R.id.editText9);
 }

Call setUpView() before setUpFocus() in onCreate().

Had the same problem recently and found out that it will work if you use setOnTouchListener instead of setOnClickListener. In the onTouch method use MotionEvent.ACTION_DOWN or MotionEvent.ACTION_UP, according to what you need. Also don't forget to return FALSE for events that also have to be processed by the system (if you want to be safe, always return false).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!