I need to set text color in adapter class not on activity and using color value that record in colors.xml file !
and this is the code: sorry for any missing things and this is the code: sorry for any missing things and this is the code: sorry for any missing things
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.myViewHolder> {
private final LayoutInflater inflater;
ArrayList<HashMap<String, String>> productsHashMapList;
/*int[] images = {
R.drawable.ic_launcher_foreground,
R.drawable.ic_launcher_background,
R.drawable.ic_launcher_foreground
};*/
public MyAdapter(Context context, ArrayList<HashMap<String, String>> productsJsonList){
inflater = LayoutInflater.from(context);
this.productsHashMapList = productsJsonList;
}
@Override
public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_row,parent,false);
myViewHolder holder = new myViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(myViewHolder holder, int position) {
holder._productName.setText(productsHashMapList.get(position).get("name"));
holder._productName.setTextColor(getResources().getColor(R.color.colorRed));
}
@Override
public int getItemCount() {
return productsHashMapList.size();
}
public class myViewHolder extends RecyclerView.ViewHolder {
ImageView _imgview;
TextView _productName;
public myViewHolder(View itemView) {
super(itemView);
_imgview = (ImageView) itemView.findViewById(R.id.logo);
_productName = (TextView) itemView.findViewById(R.id.productName);
}
}
}