use of de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ItemHighscoreBinding in project RSAndroidApp by RailwayStations.
the class HighScoreAdapter method getView.
@Override
@NonNull
public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
var rowView = convertView;
// reuse views
final ItemHighscoreBinding binding;
if (rowView == null) {
binding = ItemHighscoreBinding.inflate(context.getLayoutInflater(), parent, false);
rowView = binding.getRoot();
rowView.setTag(binding);
} else {
binding = (ItemHighscoreBinding) rowView.getTag();
}
final var item = highScore.get(position);
binding.highscoreName.setText(item.getName());
binding.highscorePhotos.setText(String.valueOf(item.getPhotos()));
binding.highscorePosition.setText(String.valueOf(item.getPosition()).concat("."));
switch(item.getPosition()) {
case 1:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_gold);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
case 2:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_silver);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
case 3:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_bronze);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
default:
binding.highscoreAward.setVisibility(View.GONE);
binding.highscorePosition.setVisibility(View.VISIBLE);
break;
}
if (position % 2 == 1) {
rowView.setBackgroundResource(R.drawable.item_list_backgroundcolor);
} else {
rowView.setBackgroundResource(R.drawable.item_list_backgroundcolor2);
}
return rowView;
}
Aggregations