Kurlicue Kurlicue - 2 years ago 120
Java Question

Android: customize a single row in RecyclerView

I have a recyclerView behanving like a list, how do I change the background color of only one view? The item I want to change the color's ID is "1", I thought about getting it in the activity by it's ID and add it a decorator, but I don't know how to, or if it's even possible.

Inside the adapter:

public void onBindViewHolder(ViewHolder holder, int position) {
holder.setEventNameName(i + "");


static int i;
class ViewHolder extends RecyclerView.ViewHolder{

public TextView eventName;
public RelativeLayout theLayout;

public ViewHolder(final View itemView) {
eventName = (TextView)itemView.findViewById(R.id.eventName);
theLayout = (RelativeLayout)itemView.findViewById(R.id.backgroundevent);


theLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (getAdapterPosition()>0){
}else {


public void settheColor(int theColor){

public void setEventNameName(String TheEventName){


Answer Source

I feel you can do it in this way --

public void onBindViewHolder(MyViewHolder holder, int position) {
    currentListItem = List.get(position);
    if(position == 0) //this will let you know the first child item

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download