在我的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方法调用了适配器。但现在我不知道如何点击这个项目。
答案 0 :(得分:0)
初始化列表视图的地方可以使用此代码。
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
}
});
答案 1 :(得分:0)
只需在你的持有人中执行此操作:
itemView.setOnClickListener { yourFunction() }