android get view id code example

Example: view.getId is giving error when is set

public static class ListMenuRowViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    protected NetworkImageView thumbnail;
    protected TextView itemname;
    protected TextView price;
    protected TextView itemtype;
    protected TextView quantity;
    protected ImageView add;
    protected ImageView sub;
    protected ImageView imageView;
    protected CardView item_layout;

    public ListMenuRowViewHolder(View itemView) {
        super(itemView);

        this.thumbnail = (NetworkImageView) itemView.findViewById(R.id.recom);
        this.imageView = (ImageView) itemView.findViewById(R.id.categ);
        this.itemname = (TextView) itemView.findViewById(R.id.itemvalue);
        this.add = (ImageView) itemView.findViewById(R.id.add);
        this.sub = (ImageView) itemView.findViewById(R.id.sub);
        this.price = (TextView) itemView.findViewById(R.id.price);
        this.quantity = (TextView) itemView.findViewById(R.id.quantity);

        this.add.setOnClickListener(this);
        this.sub.setOnClickListener(this);
        //Do this for each view
    }

    @Override
    public void onClick(View v) {
        Log.e("myname", "rohit");
        ItemscardClickListener.onClick(v, getAdapterPosition());
    }
}

Tags:

Misc Example