动态Cardview,点击不起作用

时间:2019-01-17 16:57:20

标签: android kotlin onclicklistener

我从Firestore带来了信息,它很好地完成了列表,但是在单击的那一刻,听到了声音,但是它起作用了。

val card_view = CardView(this)
    card_view.id = idCardV
    val layoutParams = LayoutParams(
        LayoutParams.MATCH_PARENT,
        LayoutParams.WRAP_CONTENT
    )
    layoutParams.bottomMargin = 15
    card_view.layoutParams = layoutParams
    card_view.setContentPadding(6,6,6,6)
    card_view.setCardBackgroundColor(Color.LTGRAY)
    card_view.radius = 12F
    card_view.cardElevation = 8F
    card_view.maxCardElevation = 12F
    card_view.isClickable = true
    card_view.callOnClick()
    card_view.setOnClickListener { View.OnClickListener{
        Toast.makeText(baseContext, "éxito 5", Toast.LENGTH_SHORT).show()
    } }

2 个答案:

答案 0 :(得分:0)

尝试放入card_view .focuseable = true

card_view.setOnClickListener { 
        Toast.makeText(baseContext, "éxito 5", Toast.LENGTH_SHORT).show()
    } 

答案 1 :(得分:0)

更改

card_view.setOnClickListener { View.OnClickListener{
        Toast.makeText(baseContext, "éxito 5", Toast.LENGTH_SHORT).show()
    } }

card_view.setOnClickListener { 
        Toast.makeText(baseContext, "éxito 5", Toast.LENGTH_SHORT).show()
    }