When the soft keyboard appears, it makes my EditText field lose focus

后端 未结 11 1824
名媛妹妹
名媛妹妹 2020-12-07 10:19

I\'ve got a few EditText fields in a ListView. When I tap on one of the EditText fields, the keyboard slides into view (as it should), but the EditText field I tapped loses

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 10:48

    For those who come here with Xamarin or Xamarin.Forms:

    I had the same issue as well but only with Android 5.x - all newer Versions including 8.1 worked well.

    Obviously sheltond was right by saying:

    In my case, this is happening because when the ListView resizes, it re-creates all of the list items (i.e. it calls getView() again for each visible list item).

    My listview was resizing as well and no, Franks solution to set windowSoftInputMode="adjustPan" was no option for me because that means that the keyboard moves the listview partly off the screen.

    All I had to do after hours of focus-debugging was setting the cell caching strategy of the Xamarin Forms ListView:

    From

    CachingStrategy="RecycleElement"
    

    To

    CachingStrategy="RetainElement"
    

    This will stop the cells from being recreated. However, this might result in bad performance and high memory consumption for huge lists. Be aware.

提交回复
热议问题