2016-02-13 119 views
0

我有這個RecyclerView,它顯示了一個名單,電話和生日的人名單。如何以編程方式更改一個RecyclerView項目樣式?

我想改變,如果今天的人的生日是商品的顏色,但我想知道如果我應該做的核實和改變我的RecyclerView's適配器OnBindViewHolder方法裏面,或者我應該做這裏面我活動調用我的LinearLayoutManager或使用RecyclerView.getChildAt()方法調用該項目。

我應該去第一個選項,使用onBindViewHolder

回答

1

。如果您選擇在onBindViewHolder()中進行更改。 我們將採取抽樣:

@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 
    } 
} 

希望它能幫助:)

+0

謝謝,我會用這種方法堅持:) – Rafael

相關問題