I have a rank of players in a viewgroup displayed programmatically. A player has a class and a method to show it inside the viewgroup:
public void show(Activity a, ViewGroup container)
{
LayoutInflater inflater = (LayoutInflater) a.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
int res = position == 1 ? R.layout.ins_rank_first : R.layout.ins_rank;
View view = inflater.inflate(res, container, false);
CircleImageView imgUser = view.findViewById(R.id.img_rank_user);
TextView txtUser = view.findViewById(R.id.txt_rank_user);
TextView txtPosition = view.findViewById(R.id.txt_rank_position);
TextView txtScore = view.findViewById(R.id.txt_rank_score);
//load image inside imageview
a.loadImage(userImage, imgUser, R.drawable.ic_profile);
if(position == 2)
imgUser.setBorderColor(a.getResources().getColor(R.color.silver));
else if(position == 3)
imgUser.setBorderColor(a.getResources().getColor(R.color.bronze));
txtUser.setText(username);
txtPosition.setText(String.valueOf(position));
txtScore.setText(String.valueOf(score));
container.addView(view);
}
So I want to ask the server every 5 seconds to generate a new ranking to make it real-time, but I don't want to remove all ViewGroup's views because the list could be long. Therefor I would like to compare new ranking positions to older ones and then exchange views when needed. How could I achieve this?