Answer the question
In order to leave comments, you need to log in
ListView not updating when I use RxJava in widget?
In the ListView of the widget, I display data from the Room DB using RxJava, but the data is not updated immediately, but only when I click the "Update" button, which calls the updateAppWidget() function.
class ListViewAdapter(ctx: Context, intent: Intent): RemoteViewsService.RemoteViewsFactory {
private var context: Context? = null
private var widgetId = 0
var data: ArrayList<String>? = null
init {
context = ctx
widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
// get data
}
override fun onCreate() {
data = ArrayList()
getList()
}
override fun onDestroy() {}
override fun getCount(): Int {
return data!!.size
}
override fun getViewAt(position: Int): RemoteViews {
val rView = RemoteViews(context!!.packageName, R.layout.list_view)
rView.setTextViewText(R.id.myTextView, data!![position].name)
return rView
}
...
override fun onDataSetChanged() {
// do nothing
}
...
fun getList() {
val v = AIWdataRepositoryGet()
Observable.fromIterable(listOfIds.toSet())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMapSingle {
userDatabase.userDao().getById(it)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
.toList()
.map {
it.map {
InfoStruct(
it.Name.toString(),
it.Id.toString()
)
}
}
.subscribe(
{
for(c in it) {
data!!.add(c.userName)
}
onDataSetChange()
},
{ onError }
).toString()
}
}
Answer the question
In order to leave comments, you need to log in
When the data changes, your method, onDataSetChanged , is called, but you do nothing in it. And how cool would it be to do the same thing that you do when you click the "Update" button
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question