I currently have a Recycler View, When the user clicks a button from the view it goes to a new activity. I would like to set the Title in the Actionbar of the new activity to that of the colour in the recycler view. So in my Example below I would like to be able to change the 'London Overground' title to the same color as the Recycler view item.
I have an array which holds the RGB color values, which is in my onBindViewHolder method. I'm able to pass the name through, just not the correct color. Please see my code below.
LineAdapter
public class LineAdapter extends RecyclerView.Adapter<LineAdapter.LineViewHolder> {
private List<Line> lineList;
public LineAdapter(List<Line> lineList) {
this.lineList = lineList;
}
@Override
public LineViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.line_list_row, parent, false);
return new LineViewHolder(itemView);
}
@Override
public void onBindViewHolder(LineViewHolder holder, int position) {
holder.lineName.setText(lineList.get(position).getLineName());
holder.lineStatus.setText(lineList.get(position).getLineStatus());
Integer[] colors = {Color.rgb(179, 99, 5),Color.rgb(227, 32, 23),Color.rgb(255, 211, 0),Color.rgb(0, 120, 42),Color.rgb(0, 164, 167),Color.rgb(243, 169, 187),Color.rgb(160, 165, 169),Color.rgb(238, 124, 14),Color.rgb(155, 0, 86),Color.rgb(0, 0, 0),Color.rgb(0, 54, 136),Color.rgb(113, 86, 165),Color.rgb(0, 152, 212),Color.rgb(149, 205, 186)};
holder.lineName.setBackgroundColor(colors[position]);
}
@Override
public int getItemCount() {
return lineList.size();
}
public class LineViewHolder extends RecyclerView.ViewHolder {
public TextView lineName;
public TextView lineStatus;
public LineViewHolder(View view) {
super(view);
lineName = (TextView) view.findViewById(R.id.lineName);
lineStatus = (TextView) view.findViewById(R.id.lineStatus);
}
}
}
My onCLick listener
recyclerView.addOnItemTouchListener(new touchListener(getApplicationContext(), recyclerView, new clickListener() {
@Override
public void onClick(View view, int position) {
String a = ( lineList.get(position).getLineName());
// Toast.makeText(line_activity.this, a, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(line_activity.this, line_info.class);
intent.putExtra("string", a);
startActivity(intent);
}
}
)
);