簡體   English   中英

單擊ViewHolder中的RecyclerView項目

[英]Click on RecyclerView item in ViewHolder

在我的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() }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM