点击ViewHolder中的RecyclerView项目

在我的ViewHolder中,我有一个函数:

private fun setupAmountLabel(amountLabelView: CategorizedAmountView, category: Category?, amount: Double, percent: String, isParentView: Boolean) { amountLabelView.setTitle(category?.getLocalizedName() ?: "") amountLabelView.setSubTitle(percent) amountLabelView.setAmountSignType(AmountType.NEGATIVE) amountLabelView.setAmountAndCurrencyCode(amount, currencyCode) amountLabelView.setIconCategory(category) amountLabelView.setAmountColor(amount.toDataSetColor()) amountLabelView.setOnClickListener { listItemClickListener?.onListItemClick(if (isParentView) 1 else 0, category?.guid ?: "") } } 

在哪里我想点击我的listItemParent。 早些时候,这个函数在适配器中,我通过创建setListClickListener方法来调用适配器。 但是现在我不知道如何点击这个项目。

你在哪里初始化列表视图可以使用这个代码。

 listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); 

要么

 listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public boolean onItemClick(AdapterView<?> parent, View view, int position, long id) { //here you can use the position to determine what checkbox to check //this assumes that you have an array of your checkboxes as well. called checkbox } }); 

只需在你的持有人内部进行:

 itemView.setOnClickListener { yourFunction() }