Android Kotlin / Anko-notifyDataSetChanged()不刷新

时间:2018-08-24 10:08:18

标签: android kotlin realm notifydatasetchanged anko

notifyDataSetChanged(),我正在UI活动中使用...

如果我打开和关闭视图,它将“刷新”视图...从RealmDB中读取

我在做什么错?

预先感谢

弗朗切斯科

class MainActivityUI : AnkoComponent<MainActivity> {
override fun createView(ui: AnkoContext<MainActivity>)= with (ui) {

    val list: ArrayList<RouletteRealmObject> = ArrayList(RouRealmManager().findAll())
    val mAdapter = RouAdapter(list)

    verticalLayout {

        linearLayout {
            lparams(width = matchParent, height = wrapContent)

            button("ADD") {
                                   onClick {

                                       alert {
                                           var newRouName: EditText? = null
                                           var newRouCasino: EditText? = null

                                           customView {
                                               verticalLayout {
                                                   textView("NEW ROULETTE")
                                                   newRouName = editText { hint = "Name" }
                                                   newRouCasino = editText { hint = "Casino" }
                                               }
                                           }
                                           positiveButton("OK") {

                                               RouRealmManager().insert("${newRouName!!.text}", "${newRouCasino!!.text}")
                                               toast("new roulette ${newRouName!!.text} form casino ${newRouCasino!!.text}")
                                               mAdapter.notifyDataSetChanged()

                                           }
                                       }.show()
                                   }
            }.lparams(width = matchParent, height = wrapContent)
        }

        recyclerView {
            lparams(width = matchParent, height = wrapContent)
            layoutManager = LinearLayoutManager(ctx)
            adapter = mAdapter
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

尝试

class MainActivityUI : AnkoComponent<MainActivity> {

   override fun createView(ui: AnkoContext<MainActivity>)= with (ui) {
     val list = RouRealmManager().findAll()           
     val mAdapter = RouAdapter(list)
     list.addChangeListener(RealmChangeListener {
         mAdapter.notifyDataSetChanged()
     })