我的數據集有一個元素userId
。我想檢查頭寸userId
是否等於userId
之前的頭寸,然後TextView
設置爲GONE
。如何根據recyclerview Android的位置動態地更改佈局中的元素?
我在onBindViewHolder
到目前爲止已經試過:
final Item item = itemsArray.get(position);
if(position - 1 > -1){
if(items.get(position-1).getUserId() == item.getUserId()) {
holder.username.setVisibility(View.GONE);
}
}
,但最終,一些具有相同userId
他們username
該項目是gone
,但他們中的一些,其userId
不相同與前位置的userId
username
也是gone
。
爲了說清楚,我附上了一些圖片,清楚地顯示出我想要的。
這就是我想要的東西:
但最終,它變成像下面的圖片,你看到item
不同userId
,該username
也`不見了。
所以,我的問題是,我怎麼能檢查前一個項目的userId
是一樣的當前位置的userId
,所以它不會落得我附着在第二圖像。
如果有其他解決方案,請讓我知道。提前感謝。
是您的userId是字符串類型? –
是'int'類bro – ken
嘗試添加其他條件邏輯爲「holder.username」 –