9

I have implemented a RecyclerView with SearchView and Filterable; all classes from v7. Now there is this behavior that is annoying. Whenever the keyboard is brought up or closed the contents of the RecyclerView goes blank. The count is still correct but the view is empty. My guess, it has something to do with the Layout size change. Is this behavior normal or something is wrong? How to deal with it? I can show the code but don't quite know which part will be relevant so tell me what can I add here?

priyank
  • 2,553
  • 4
  • 21
  • 33

2 Answers2

16

While typing in the question, found this from the similar questions.

Please add following line to your activity in manifest. Hope it works. android:windowSoftInputMode="adjustPan"

More precisely, add android:windowSoftInputMode="adjustPan" in the activity tag in AndroidMenifest.xml where the keyboard is going to be opened.

Example:

<activity
        android:name=".FManagerActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan"
        android:theme="@style/AppTheme.Light.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

It is basically the behavior in which the activity reacts when the keyboard is opened or closed. adjustPan tells the keyboard to overlay the view of the activity not disturbing it's content. Without that when the keyboard is opened the size of the activity also changes which makes the content disappear as notifyDatasetChanged() is not called during and after the implicit actions.

priyank
  • 2,553
  • 4
  • 21
  • 33
0

Not really sure why but setting it as SOFT_INPUT_ADJUST_RESIZE solved the issue for me:

activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
Francislainy Campos
  • 1,743
  • 11
  • 36
  • 1
    Setting `SOFT_INPUT_ADJUST_RESIZE` will resize the activity which will lead to recreation of activity (unless handling manually using `android:configChanges="screenSize"`). You must save activity state and retain in `onCreate`. – priyank Sep 30 '18 at 20:50