我无法更改 onDataChange 函数中的文本视图

问题描述 投票:0回答:0

我想更新一个从 Firebase-Realtime-Database 获取数据的 textView。 textview 更新代码嵌套在 onDataChange 函数中,该函数又嵌套在 一个 onClickListener.

Code

db.addValueEventListener(object : ValueEventListener {
                override fun onDataChange(dataSnapshot: DataSnapshot) {
// This method is called once with the initial value and again
                    // whenever data at this location is updated.
                    val value = dataSnapshot.getValue(String::class.java)


                    if (value != null) {
                        arrayList.add(value)
                    }
                    myArr.notifyDataSetChanged()
                    //listView.adapter=myArr




                    println( "Value is: $value")
                    if (dataSnapshot !=null) {
                        Thread.sleep(1000)
                        val name = value.toString()
                        println("testing $name")
                        textView2.text=name
                    }


                    textView2.text=name




                }

请发送帮助

android firebase kotlin firebase-realtime-database textview
© www.soinside.com 2019 - 2024. All rights reserved.