Я использую recycler-view
, и я хочу, чтобы элементы в нечетных строках имели более темный оттенок, теперь мне удалось сделать это в OnBindViewHolder, но проблема в том, что если я изменю DataSet, то тамстроки, которые складываются друг в друга с одним и тем же цветом ...
Я понял, что если использовать notifyDataSetChanged
, то это должно исправить это, но, как я понял, использование notifyDataSetChanged
неэффективнопоэтому я ищу лучшие способы исправить это. Заранее большое спасибо.
public void onBindViewHolder(@NonNull StandingsHolder holder, int position) {
StandingsDetail currentStandingsDetail = standingsDetail.get(position);
String playerName = (position+1) + " " + currentStandingsDetail.player.getFirstName() + " " + currentStandingsDetail.player.getLastName();
holder.name.setText(playerName);
holder.rating.setText(String.valueOf(currentStandingsDetail.standings.getRating()));
holder.games.setText(String.valueOf(currentStandingsDetail.standings.getGames()));
holder.wins.setText(String.valueOf(currentStandingsDetail.standings.getWins()));
holder.losses.setText(String.valueOf(currentStandingsDetail.standings.getLosses()));
holder.goals.setText(String.valueOf(currentStandingsDetail.standings.getGoals()));
holder.assists.setText(String.valueOf(currentStandingsDetail.standings.getAssists()));
if(position % 2 == 1){
holder.itemView.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.dark_overlay)));
}
}
проблема: https://imgur.com/a/TBTipZS