last day (16 days later) » 

20:54
0
Q: RecyclerView - notifyDataSetChanged Only Works After 1 Millisecond Delay

RoymunsonI am creating a custom keyboard app, which uses a InputMethodService. I've noticed something very odd. If I call mainview.tabRecyclerView.adapter.notifyDataSetChanged() (mainview.tabRecycler is a recycler view, which I can reference like this due to Kotlin extensions) inside of the overrided on...

if you use mainview.tabRecyclerView.adapter = then you dont need to call notifyDataSetChanged() at all
@MarkKeen sure, no problem
@pskink Setting the adapter and not calling notifyDataSetChanged() doesn't do anything. I believe either [A] the adapter must be set after the onCreateInputView method has been finished or [B] if the adapter is set before onCreateInputView is finished, then notifyDataSetChanged() must be called after onCreateInputView is finished.
if you call RecyclerView#setAdapter() there is no need for calling notifyDataSetChanged() method - you call it only if your data model has changed in some way
@pskink I know I can just call setAdapter(), but for some reason setAdapter() does not work if I call it while onCreateInputView() has not finished. I need to call setAdapter() once onCreateInputView() has finished running and returned the object mainview. Unfortunately, I can't call setAdapter() from within a coroutine, so I'm forced to call setAdapter() inside onCreateInputView() and use a coroutine to call notifyDataSetChanged() with a delay of 1 milliseconds, so I know that onCreateInputView has finished
i have no time to verify this (you know real madrid vs liverpool) - but seeing the docs i think you can override onStartInputView (or onBindInput) - first add some Log.d inside and see when they are called
20:54
@pskink It seems like onStartInputView is called after onCreateInputView. So, setting my adapters in that method could work. However, looking at the documentation for that method, it seems like that is not the proper place to set my adapters/use notifyDataSetChanged().
"Called when the input view is being shown and input has started on a new editor. This will always be called after onStartInput(EditorInfo, boolean), allowing you to do your general setup there and just view-specific setup here." - why not a proper place?
@pskink Apologies, the documentation also says "to deal with input starting within the input area of the IME." in reference to onStartInputView, which made me think that it was called if you had a search bar (or EditText) within a custom keyboard. Now I'm confused because the sentence I found from the documentation and the sentences you found within the documentation seem to contradict, even though they are from the same document located at: developer.android.com/reference/android/inputmethodservice/…
so mainview.tabRecyclerView.adapter = ... (without notifyDataSetChanged) works there?
actually i have no idea what they mean by "to deal with input starting within the input area of the IME." - i think that docs describing the method are better
ok this sample: pastebin.com/raw/a8kt0L6v shows RecyclerView with 3 items - it does nothing but RV is shown and adapter is functional, btw do you know why no Log.d is shown on the logcat?
In response to your question - for some reason mainview.tabRecyclerView.adapter = ... (with or without notifyDataSetChanged) afterwards works, but inconsistently.
For example - sometimes when I open my keyboard, the recyclerview will show its items
but other times, the recyclerview will not show any items
So, moving the code to onStartInputView is a partial improvemnet
Also, in regards to your question about why no Log.d is shown on logcat, I'm a little confused because the code you sent does not have any Log.d() method

  last day (16 days later) »