Rafael
Rafael

Reputation: 1487

How to programmatically change one RecyclerView item style?

I've got this RecyclerView, it's showing a list of persons with their names, phones and birthday.

I want to change the color of the item if the person's birthday is today, but I want to know if I should do the verification and change on my RecyclerView's adapter inside the OnBindViewHolder method, or if I should do it inside my activity calling my LinearLayoutManager or calling the item using the RecyclerView.getChildAt() method.

Should I go whit the first option, using the onBindViewHolder?

Upvotes: 0

Views: 1226

Answers (1)

OBX
OBX

Reputation: 6114

YES . Should you choose to make changes in the onBindViewHolder(). We'll take a sample:

 @Override
public void onBindViewHolder(FeedsViewHolder feedViewHolder, int i)
{       

    if(d1.feeds.get(i).getFeedContentType().equals("b-day")) // <-- Pointing to the List that contains value, and checks if it equals to a sample string
    {
        feedViewHolder.n1.setText("Birthday"); // <-- if it equals, party time :D , and sets text to the corresponding TextView in the RecyclerView
    }
}

Hope it helps :)

Upvotes: 1

Related Questions