mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

CustomView is not clickable #2714

Closed PembaTamang closed 3 years ago

PembaTamang commented 3 years ago

I am using version 8.3.1 Here is my custom view code.

class CustomHeader(private val loginClick: HeaderLoginClick) : AbstractDrawerItem<CustomHeader, CustomHeader.ViewHolder>() {
    override val type: Int
        get() = R.id.custom_header

    override val layoutRes: Int
        @LayoutRes
        get() = R.layout.custom_header

    override fun bindView(holder: ViewHolder, payloads: List<Any>) {
        super.bindView(holder, payloads)
        val ctx = holder.itemView.context
        holder.itemView.id = hashCode()
        //define how the divider should look like
        holder.itemView.isClickable = true
        holder.itemView.isEnabled = true
        holder.itemView.minimumHeight = 1
        holder.itemView.topLine.tag = "Login Button"
        holder.itemView.setOnClickListener {
            loginClick.LoginClick()
            mlog("login view clicked")
        }
        holder.itemView.topLine.setOnClickListener {
            mlog("login button clicked, tag = ${it.tag}")

        }
        ViewCompat.setImportantForAccessibility(holder.itemView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO)
        onPostBindView(this, holder.itemView)
    }

    override fun getViewHolder(v: View): ViewHolder {

        return ViewHolder(v)
    }
    interface HeaderLoginClick{
        fun LoginClick()
    }
    class ViewHolder internal constructor(view: View) : RecyclerView.ViewHolder(view){

    }
}

Setting the view as clickable and enabled does not work. setting the click listener on the entire view does not work nor does setting it to an individual view. I was trying to use the interface to send the tag (LoginButton) to identify the different views when clicked. Is there a better way to do it? Also how do I update the texts of those individual views when needed. Please help

mikepenz commented 3 years ago

@PembaTamang the FastAdapter will prevent click listeners on the itemView

Please use the click listeners exposed by the drawer and FastAdapter. If you want a sub-view be clickable, please use the EventHooks exposed by the FastAdapter

More details on the underlaying adapter: https://github.com/mikepenz/FastAdapter

PembaTamang commented 3 years ago

I see, thanks. Thanks again for this amazing library and quick response. I had another query unrelated to this library, do you have courses online on udemy, courseEra or even a youtube channel ?