dae*_*ick 0 kotlin android-studio android-recyclerview
我正在使用 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)
首先,您可以将此代码移动到onclickListner.
paymentList= paymentDb?.paymentDao()?.getAll()!!
mAdapter = PaymentRecylcerViewAdapter(this, paymentList)
mAdapter.notifyDataSetChanged()
orderRecyclerview.adapter = mAdapter
orderRecyclerview.layoutManager = LinearLayoutManager(this)
orderRecyclerview.setHasFixedSize(false)
Run Code Online (Sandbox Code Playgroud)
然后在onClickListner句柄内的可见性orderRecyclerview。
为了更好的用户体验,您还可以在此添加动画。希望,它会有所帮助。
| 归档时间: |
|
| 查看次数: |
415 次 |
| 最近记录: |