简体   繁体   中英

Android Kotlin/Anko - notifyDataSetChanged() doesn't refresh

notifyDataSetChanged() , I'm using in the UI activity...

It "refreshes" the view if I open and close it... reading it from RealmDB

what am I doing wrong?

thanks in advance

Francesco

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
        }
    }
}

}

Try this

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()
     }) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM