简体   繁体   中英

Click on RecyclerView item in ViewHolder

In my ViewHolder i have a function:

    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 ?: "")
    }
}

Where i want to click on my listItemParent. Earlier this function was in the adapter, and I called the adapter by creating the setListClickListener method. But now i didn t know how i can make click on this item.

where you initialized the list view can able to use this code.

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

                }
            });

or

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() }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM