Keyboard Changes When Item Scrolled Offscreen

Nathan Sokalski 4,116 Reputation points
2021-12-01T05:44:52.527+00:00

I have a RecyclerView whose items contain an EditText. Selecting an EditText opens the keyboard and does everything I want & expect. However, if I then scroll far enough that the selected EditText is offscreen, the keyboard changes and the EditText loses focus. Losing focus is expected, but since the EditText is no longer focused, I would also expect the keyboard to close. The keyboard does not close, but it does change. What changes is that the numbers (the top row of keys containing 0...9) get removed from the keyboard. I am debugging using a Surface Duo, so I am using SwiftKey. I am guessing that the fact that the EditText is no longer focused is causing Android to choose a different keyboard, since the numbers return once I reselect an EditText. My problem is that when I select another item/EditText, the RecyclerView scrolls to the appropriate position, but then changes the keyboard, therefore making it no longer the appropriate position. Why does the keyboard change instead of close?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,656 Reputation points Microsoft Vendor
    2021-12-02T07:10:25.07+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Why does the keyboard change instead of close? I think this issue is related to the item reusable, when item(Edittext) is disappear, this item do not destoryed, it be re-usabled by recycleview.

    If you want to hide the keyboard when item is disappear, we can hide the keyborad when recycleview was touched.

       mRecyclerView.SetOnTouchListener(new MyTouchListener(this));  
        internal class MyTouchListener : Java.Lang.Object, View.IOnTouchListener  
           {  
               private MainActivity mainActivity;  
         
               public MyTouchListener(MainActivity mainActivity)  
               {  
                   this.mainActivity = mainActivity;  
               }  
         
               public bool OnTouch(View v, MotionEvent e)  
               {  
                   InputMethodManager imm = (InputMethodManager)mainActivity.GetSystemService(Context.InputMethodService);  
                   imm.HideSoftInputFromWindow(v.WindowToken, 0);  
                   return false;  
               }  
           }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.