butterknife @OnClick inside ViewHolder in CustomAdapter

前端 未结 4 1929
耶瑟儿~
耶瑟儿~ 2021-01-13 20:59

I\'m currently learning butterknife, and I need to bind specific @OnClicks on different views generated by my customer adapter. How do I go about with this?

I\'ve se

4条回答
  •  星月不相逢
    2021-01-13 21:39

    write this code in ViewHolder class

    static class ViewHolder {
        public int getPosition;
    
        @Nullable
        @Bind(R.id.txt_title_name)
        TextView txtTitle;   
    
     public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    
    
        @OnClick(R.id.btn_download)
        public void onCheck() {
            Log.d("ViewHolder", "position ->" + getPosition);
        }
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
    holder.getPosition = position;
    }
    

提交回复
热议问题