小编dae*_*ick的帖子

单击按钮时,如何折叠和展开回收站视图布局?

我正在使用 Kotlin 开发回收器视图。让我们看看我的代码,当我点击 orderProduct 按钮时,orderRecyclerview 是可见的,相反,当我再次点击时,可见的消失了。但有时当我点击它时,会显示回收站视图,有时不显示。那么我怎样才能随时做到这一点呢?我该如何解决这个错误?

 orderProduct.setOnClickListener{

            orderProduct.setCompoundDrawablesWithIntrinsicBounds(0, 0, if (!isClicked) R.drawable.btn_down else R.drawable.btn_up, 0)

                if (isClicked) {

                    var r = Runnable {

                        try {
                            orderRecyclerview.visibility=View.VISIBLE
                            paymentList= paymentDb?.paymentDao()?.getAll()!!
                            mAdapter = PaymentRecylcerViewAdapter(this, paymentList)
                            mAdapter.notifyDataSetChanged()

                            orderRecyclerview.adapter = mAdapter
                            orderRecyclerview.layoutManager = LinearLayoutManager(this)
                            orderRecyclerview.setHasFixedSize(false)

                        }catch (e: Exception) {

                        }
                    }
                    val thread = Thread(r)
                    thread.start()

                }else {
                    orderRecyclerview.visibility=View.GONE
                }

            isClicked = !isClicked

            }
Run Code Online (Sandbox Code Playgroud)

kotlin android-studio android-recyclerview

0
推荐指数
1
解决办法
415
查看次数