mercredi 11 décembre 2019

How to make select all checkbox work in kotlin?

I made selectAll checkbox. and then I tried to make selectall checkbox work. but when I clicked selectall just first recyclerview item checkbox change. So How can I make that all recyclerview item checkbox drawable will be change?

class CartViewActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefreshListener {

    private val tag = this::class.java.simpleName

    lateinit var adapter: CartItemRecyclerAdapter

  var itemList: MutableList<CartItemDataVo> = arrayListOf()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_cart_view)

    SelectAll.setOnClickListener {

      if(SelectAll.isChecked){
         SelectAll.buttonDrawable=it.context.getDrawable(R.drawable.check_box_active_cs)
         checkBox.buttonDrawable=it.context.getDrawable(R.drawable.check_box_active_cs)

          else {
          SelectAll.buttonDrawable= it.context.getDrawable(R.drawable.check_box_no)
          checkBox.buttonDrawable= it.context.getDrawable(R.drawable.check_box_no)

        }

        }
       swipeRefreshLo.setOnRefreshListener(this)


        itemList.add(CartItemDataVo("item1", 1, 16800, "cart_doll"))
        itemList.add(CartItemDataVo("item2", 1, 16800, "cart_cup"))
        itemList.add(CartItemDataVo("item3", 1, 30000, "cart_perfume"))
        itemList.add(CartItemDataVo("item4", 1, 16800, "cart_fan"))
        itemList.add(CartItemDataVo("item5", 1, 16800, "cart_bear"))

        val itemRecyclerAdapter = CartItemRecyclerAdapter(this, this , itemList)

        recycler_view.adapter = itemRecyclerAdapter
        recycler_view.layoutManager = 
        androidx.recyclerview.widget.LinearLayoutManager(applicationContext)      
    }

    override fun onRefresh() {
        swipeRefreshLo.isRefreshing = false
    }
}






Aucun commentaire:

Enregistrer un commentaire