3Answers
  • 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Android Viewgroup Issues

I have an issue using a viewGroup, for some reason the id doesn't process the statement, and really I tried everything, can you help please?

I don't know if it is something about the version3.3.2 or what's wrong with the code

public class popularAdapter extends  RecyclerView.Adapter<popularAdapter.ImageViewHolder> {

    private Context mContext;
    private List<popular> mPopulars;

    public popularAdapter (Context context,List<popular>populars){

        mContext=context;
        mPopulars=populars;



    }




    @Override
    public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                                                      //HERE IS THE ISSUE
        View v= LayoutInflater.from(mContext).inflate(R.layout.popular_item2,viewGroup,false);

        return new ImageViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ImageViewHolder holder, int position) {

    popular popularCur=mPopulars.get(position);
    ImageViewHolder.prodName.setText(popularCur.getProduc_name());


    }

    @Override
    public int getItemCount() {
        return 0;
    }

    public class ImageViewHolder extends RecyclerView.ViewHolder {

        public TextView prd_name;
        public TextView prd_price;
        public TextView prd_img;

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

            prd_name =itemView.findViewById(R.id.prodName);
            prd_price=itemView.findViewById(R.id.prodPrice);
            prd_img  =itemView.findViewById(R.id.prodImageHolder);




        }
    }

}

problem is here

you will never get any items in RecyclerView because you are returning 0 in getItemCount

    @Override
    public int getItemCount() 
    {
       //return 0 ?
        return 0;
    }

change with

    @Override
    public int getItemCount() 
    {
        return mPopulars.size();
    }

getItemCount

int getItemCount ()

Returns the total number of items in the data set held by the adapter.

  • 1
Reply Report

Try this solution

public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View v= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.popular_item2,viewGroup,false);
    return new ImageViewHolder(v);
}
  • 0
Reply Report

Optimizing @Ashwin solanki answer

Change following code

@Override
public int getItemCount() 
{
   //return 0 ?
    return 0;
}

to

@Override
public int getItemCount() 
{
   //return 0 ?
    if(mPopulars != null) {
        return mPopulars.size();
    }
    return 0;
}

Description: onCreateViewHolder and onBindViewHolder methods get called for the count which is returned by getItemCount method. As your code is always returning 0, these methods will not get called and list will not get populated on UI.

Also, check following line from you code from onBindViewHolder method:

ImageViewHolder.prodName.setText(popularCur.getProduc_name());

You are considering 'prodName' variable of 'ImageViewHolder' class as static but it is not. Instead it should be

holder.prodName.setText(popularCur.getProduc_name());
  • 0
Reply Report