Search code examples
javaandroidkotlinonclickandroid-linearlayout

how to dismiss changes from onclicklistener on click again in Kotlin?


i have this clicklistener:

holder.linearLayout_soul_bg.setOnClickListener {

            setBackgroundColor(R.color.soul_bg)
            holder.inspirationtext.setTextColor(Color.WHITE)
            holder.like.setImageDrawable(getResources().getDrawable(R.drawable.cancle_soul))
            holder.inspiration_title.setTextColor(Color.WHITE)
            holder.sourcetext.setTextColor(Color.WHITE)
            holder.sharetext.setTextColor(Color.WHITE)
            holder.sharetext.setBackgroundResource(R.drawable.small_share_bg_white)
        }

that makes changes on the design if the user click on it

how can i undo these changes if the user click again?


Solution

  • i used isSelected as follow:

    holder.linearLayout_soul_bg.setOnClickListener {
    
    
                it.isSelected = !it.isSelected
                if (it.isSelected) {
                    //do whatever here if true
                } else {
                    //do whatever here if false
    
                }
            }