Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
public class SubCategoryListAdapter extends RecyclerView.Adapter<SubCategoryListAdapter.ViewHolder> implements View.OnClickListener 
{

    private static final String TAG = SubCategoryListAdapter.class.getSimpleName();
    private ArrayList<MasterCategory> superSubCategories;
    private ImageLoader imageloader;
    private com.amoda.androidlib.intf.OnItemClickListener mOnItemClickListener;
    private String iconImageURL;
    MerchantOrder merchantorder=new MerchantOrder();
    ArrayList<MasterCategory> productitemscount=new ArrayList<MasterCategory>();



    @Override
    public void onClick(View view)
    {
        if (mOnItemClickListener != null)
            mOnItemClickListener.onItemClick(view, (Integer) view.getTag());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView name;
        public TextView productCount;
        public NetworkImageView image;


        public ViewHolder(View itemLayoutView)
        {
            super(itemLayoutView);
            productCount = (TextView) itemLayoutView.findViewById(R.id.product_count);
            name = (TextView) itemLayoutView.findViewById(R.id.name);
            image = (NetworkImageView) itemLayoutView.findViewById(R.id.image);

        }
    }

    public SubCategoryListAdapter(ArrayList<MasterCategory> superSubCategories, String iconImageURL)
    {
        this.superSubCategories = superSubCategories;
        notifyDataSetChanged();
        imageloader = Global.getInstance().getImageLoader();
        this.iconImageURL = iconImageURL;

    }

    @Override
    public SubCategoryListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.super_category_list_row, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position)
    {
        /*new WebServicesManager().getProductByCategoryId(request);*/
     /*   updateUI(position);*/
        holder.name.setText("" + superSubCategories.get(position).getName());
        holder.image.setDefaultImageResId(R.drawable.logo_amoda);
        holder.image.setImageUrl(iconImageURL, imageloader);

        if(!superSubCategories.get(position).isHasChildCategory())
        {
            holder.productCount.setText("" + superSubCategories.get(position).setProductCount());
        }
        else
        {
            holder.productCount.setText("");
            holder.productCount.setBackgroundResource(R.drawable.icn_right_arrow);
        }
        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(this);
    }
    public void setmOnItemClickListener(com.amoda.androidlib.intf.OnItemClickListener mOnItemClickListener)
    {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    @Override
    public int getItemCount()
    {
        if (superSubCategories != null)
            return superSubCategories.size();
        else
            return 0;
    }

    public MasterCategory getSuperSubCategory(int position)
    {
        return superSubCategories.get(position);
    }
}


What I have tried:

I tried using notify methods but it's not working for me.I have this recycler view consisting of product count and in onclick on that particular item the count doesnot get updated when i try to add/delete product.
Posted
Updated 29-Jun-16 2:44am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900