Reputation: 816
I stocked in a problem. I have a listView and this listView is just for showing data row by row and items are all disabled using override function isEnabled to false. so this is my code:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/baseLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:divider="@null"
android:dividerHeight="0dp"
android:focusable="false"
android:focusableInTouchMode="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I need to set click listener on baseLayout but every thing I've done not made the focus on baseLayout and listview calls absListView touch listener. any idea? ...
Upvotes: 0
Views: 72
Reputation:
You have to set listener on list cell, such as. It is example for recyler view, but it is same case on listview.
class SearchListAdapter(private val context: Context) : RecyclerView.Adapter() {
private var products: List<Repo> = arrayListOf()
var listener: AdapterListener? = null
override fun onCreateViewHolder(parent: ViewGroup, i: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_repo, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return products.size
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
viewHolder.bind(position, products[position])
}
fun setList(contacts: List<Repo>) {
this.products = contacts
notifyDataSetChanged()
}
inner class ViewHolder(itemView: View) : BindingViewHolder<ItemRepoBinding>(itemView) {
fun bind(pos: Int, contact: Repo) {
if (binding == null) {
return
}
binding.tvTitle.text = contact.name
binding.setVariable(
BR.tintlist,
context.resources.getColorStateList(R.color.xml_color_btn_title)
)
binding.root.setOnClickListener(View.OnClickListener {
if (listener != null) {
listener?.onClick(pos, contact)
}
})
}
}
interface AdapterListener {
fun onClick(position: Int, info: Repo)
}
}
Upvotes: 1