Issues focusing EditTexts in a ListView (Android)

前端 未结 2 1480
独厮守ぢ
独厮守ぢ 2020-12-18 04:52

I have a ListView with a few EditTexts in each item. I have no issues with a hardware keyboard, but things freak out a bit with the soft keyboard. I have two issues.

<
2条回答
  •  再見小時候
    2020-12-18 05:34

    first of all when the screen loads,, focus is on the "Gr High School Scale" field, because of this in your xml. but this does no gurantee that the keyboard might show.. to make the keyboard to show use getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); also i am thinking that it looses focus immediately because the listview has taken focus away from the edittext

    
    

    , and since none of your listview edittext is asking for focus,, the focus stays on just the listview not the edittext..so you need to re-surface the focus back to the edittext..also from the android documentation it states By default the user can not move focus to a view;.. and also it states that "if focusableInTouchMode is true for a view, that view can gain focus when clicked on, and can keep focus if another view is clicked on that doesn't have this attribute set to true. " mostly when you first create an edittext it automatically adds to it specifying that it needs to take focus, or it can take focus..but in your case and with this documentaion the edittext will never keep focus because listview is taking it away from him.. so in short try this on all views(including your edittext) you want to take focus like you did on the listview

    android:focusable="true" 
    android:focusableInTouchMode="true" 
    

    so try that on the edittext and let me know if it helps..thanks for waiting

提交回复
热议问题