Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Java
public class CategoryAdapter extends RecyclerView.Adapter<categoryadapter.featuredaviewholder> {

    ArrayList<categoryhelperclass> featureLocations;

    public CategoryAdapter(ArrayList<categoryhelperclass> featureLocations) {
        this.featureLocations = featureLocations;
    }

    @NonNull
    @Override
    public FeaturedAViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.categories_card_design,parent,false);
        FeaturedAViewHolder featuredAViewHolder=new FeaturedAViewHolder(view);
        return featuredAViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull FeaturedAViewHolder holder, int position) {
        CategoryHelperClass categoryHelperClass=featureLocations.get(position);
        holder.image.setImageResource(categoryHelperClass.getImage());
        holder.title.setText(categoryHelperClass.getTitle());
        holder.relativeLayout.setBackground(CategoryHelperClass.getGradient());
    }

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

    public static class FeaturedAViewHolder extends RecyclerView.ViewHolder{
        ImageView image;
        TextView title,relativeLayout;

        public FeaturedAViewHolder(@NonNull View itemView) {
            super(itemView);

            //Hooks
            image=itemView.findViewById(R.id.category_image);
            title=itemView.findViewById(R.id.category_text);
            relativeLayout = itemView.findViewById(R.id.background_gradient);
        }
    }
}

CategoryHelperClass
Java
public class CategoryHelperClass{
 int image;
         String title,descriptions;

public CategoryHelperClass(int image, String title, String descriptions) {
        this.image = image;
        this.title = title;
        this.descriptions = descriptions;
        }

public int getImage() {
        return image;
        }

public String getTitle() {
        return title;
        }

public String getDescriptions() {
        return descriptions;
        }}


What I have tried:

I had tried to give id to realtive layout. Dont know how to pass gradient in realtive layout
Posted
Updated 7-Dec-20 1:12am
v2
Comments
David Crow 6-Dec-20 19:23pm    
"Getgradient() showing error..."

Are we supposed to guess what this error is? If you want help, at least provide the minimum information, preferably relevant.

"I had tried to give id to realtive layout. Dont know how to pass gradient in realtive layout"

What does this mean? Remember, only you know what you want your code to do.

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