开发者

Android requestFocus issue

开发者 https://www.devze.com 2023-03-03 15:40 出处:网络
I have a ViewFlipper with several LinearLayout with EditTexts; after pressing a button, there\'s some validation done, and should it开发者_开发技巧 fail, I need to set the focus to the Edit that needs

I have a ViewFlipper with several LinearLayout with EditTexts; after pressing a button, there's some validation done, and should it开发者_开发技巧 fail, I need to set the focus to the Edit that needs to be modified. vf is the ViewFlipper; et123 is an EditText. When there's an error detected, the following is executed:

 vf.setDisplayedChild(5);
 findViewById(R.id.et123).requestFocus();

The funny thing is that the first time the button is pressed, the focus goes to another element in the right Layout. If I press the button one more time, the focus goes to et123.

Any ideas on why does it happen or how to fix it?

Thanks


You might need to call

findViewById(R.id.et123).setFocusableInTouchMode(true);

Before calling requestFocus() to enable receiving focus.

0

精彩评论

暂无评论...
验证码 换一张
取 消