2017-07-06 62 views
0

在我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方法來調用適配器。但是現在我不知道如何點擊這個項目。

+0

可我知道你的適配器?它是基座適配器嗎? –

+0

@DinithePieris不,它是我的自定義適配器。 – Inkognito

+0

該方法在ViewHolder類中如何或爲什麼? – Bills

回答

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 

    } 
}); 
+0

thx回答,但首先,我用kotlin,第二我用recyclerView,我也需要調用函數在我的持有人 - 我認爲這樣 – Inkognito

0

只是這樣做你的倉內:

itemView.setOnClickListener { yourFunction() }