Click here to Skip to main content
15,949,686 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 ProgressBar progressbar ;
    private ArrayList<MasterCategory> superSubCategories;
    private int productcount;
    private ImageLoader imageloader;
    private com.amoda.androidlib.intf.OnItemClickListener mOnItemClickListener;
    private String iconImageURL;
    public TextView textError;
    private Context context ;
    MerchantOrder merchantorder=new MerchantOrder();
    ArrayList<MasterCategory> productitemscount=new ArrayList<MasterCategory>();
    private ArrayList<MasterCategory> merchantOrders;
    private ArrayList<Product> products;
    private int count;
    private ProgressDialog progressDialog;
    private IRequestComplete iRequestComplete;
    public boolean onbind;
    private boolean loading;
    private OnLoadMoreListener onLoadMoreListener;
    ArrayList<MerchantOrderItem> merchantOrderItems;

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

        //Toast.makeText(context,"onClickmethod", Toast.LENGTH_LONG).show();
        Log.d("01", "In OnClickmethod");


    }

    public class ViewHolder extends RecyclerView.ViewHolder
    {
        public TextView name;
        public TextView productCount;
        public NetworkImageView image;
        public TextView textError;
        public SwipeRefreshLayout swipeRefreshLayout;
        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);
           // textError=(TextView)itemLayoutView.findViewById(R.id.text_nodeals_error);
       //     itemLayoutView.findViewById(R.id.dashboard_progressbar_newlyadded).setVisibility(View.VISIBLE);
        //    swipe=(SwipeRefreshLayout)itemLayoutView.findViewById(R.id.swiper);

        }
    }

    public SubCategoryListAdapter(ArrayList<MasterCategory> superSubCategories, String iconImageURL)
    {
        this.superSubCategories = superSubCategories;
        imageloader = Global.getInstance().getImageLoader();
        this.iconImageURL = iconImageURL;
      //  progressDialog=UIHelper.showProgressDialog(context,"Please wait..",false,true);
        //progressbar.findViewById(R.id.dashboard_progressbar_newlyadded).setVisibility(View.GONE);
    }


    @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)
    {
      /*  if (superSubCategories !=null )
        {

            new WebServicesManager().getProductsByCategoryId(new RequestManager().getMerchantProductRequest(AmodaMerchantUser.getInstance().getMerchantProfile().getMerchantId()
                    ,superSubCategories.get(position).getCategoryId(), 1, 25), iRequestComplete);


        }
        else
        {
            iRequestComplete.onRequestComplete(null);
        }
*/

        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).getProductCount());//superSubCategories.get(position).getProductCount()); // superSubCategories.get(position).getProductCount());


            if (superSubCategories.get(position).getProductCount() == 0)
            {
                holder.productCount.setText(0);
            }

        }
        else
        {
            holder.productCount.setText("");
            holder.productCount.setBackgroundResource(R.drawable.icn_right_arrow);
        }

        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(this);

        // SubCategoryListAdapter subCategoryListAdapter=new SubCategoryListAdapter(superSubCategories,iconImageURL);
        // this.notifyDataSetChanged();
        //To Update View
        // updatelistView(position);

        //  Intent intent=new Intent();
        //   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // this.notifyDataSetChanged();

       /* swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
        {
            @Override
            public void onRefresh()
            {
                refresh();
            }
        });

    }


    private void refresh()
    {
        new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
       */


        // swipe.setRefreshing(false);
         /*   }
        },100);
    }*/
    //    int currentposition=position;

     //   MasterCategory categoriescount = superSubCategories.get(position);

     /*  if(superSubCategories!=null && superSubCategories.get(position).getProductCount()>=0)
       {
           add(currentposition);
           remove(currentposition);
       }
*/
        /*try
        {
            notifyItemChanged(position);
        }
        catch (Exception e)
        {
            Log.e("onCountchanged", e.getMessage());
        }*/

   /*     UIHelper.showProgressDialog(context,"Please wait..",false,true);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                SubCategoryListAdapter.this.notifyItemRangeChanged(0, productcount);
                //  SubCategoryListAdapter.this.notifyItemChanged(position);
                SubCategoryListAdapter.this.notifyDataSetChanged();
            }
        }, 50);*/

       /* holder.productCount.post(new Runnable()
        {
            @Override
            public void run()
            {
                notifyItemChanged(position);
                notifyDataSetChanged();
            }
        });
*/

        if(loading)
            onLoadMoreListener.onLoadMore();


    }



    private void add(int currentposition)
    {
      //  superSubCategories.add(currentposition,categoriescount);
        notifyItemInserted(currentposition);
        superSubCategories.get(currentposition).getProductCount();
    }

    private void remove(int currentposition)
    {
      //  superSubCategories.remove(currentposition);
        notifyItemRemoved(currentposition);
        superSubCategories.get(currentposition).getProductCount();
    }


    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);

    }

    public void setSuperSubCategory(ArrayList<MasterCategory> merchantOrders)
    {
        this.merchantOrders = merchantOrders;
        notifyDataSetChanged();
    }

    public void setLoaded()
    {
        loading = false;
    }

    public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener)
    {
        this.onLoadMoreListener = onLoadMoreListener;
    }
   /* public MasterCategory getSubSubCategory(int position)
    {
        return SubSubCategories.get(position);
    }*/
}


What I have tried:

I used notifydatasetchanged with my adapter to update my recyclerview data .I have also tried using handler in my activity and even swipew refresh layout view ,but still my row item is not getting updated . Any suggesstion would be appreciated.
Posted

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