app lags when scroll the recyclerview tried on physical device one plus 9 pro same thing happen minor lags when scroll. If i remove countdown it work smooth. below is my recyclerview adapter.I also used custom countdown timer in runnable class same thing lag. in first try i have created countdowntimer in onbindviewholder but according to this answer onbindview create countdown timer every time when scoll so i moved in viewholder.
public class AdapterFixturesList extends RecyclerView.Adapter<AdapterFixturesList.MyViewHolder> {
private List<BeanHomeFixtures> mListenerList;
Context mContext;
CountDownTimer timer;
public AdapterFixturesList(final List<BeanHomeFixtures> mListenerList, Context context) {
mContext = context;
this.mListenerList = mListenerList;
long maxTime = 0;
for (BeanHomeFixtures item : mListenerList) {
if (!item.getTime().equalsIgnoreCase("")) {
maxTime = Long.parseLong(item.getTime());
}
}
timer = new CountDownTimer(maxtime, 1000) {
@Override
public void onTick(long millisUntilFinished) {
for (int i = 0, dataLength = mListenerList.size(); i < dataLength; i++) {
BeanHomeFixtures item = mListenerList.get(i);
if (!item.getTime().equalsIgnoreCase("")) {
item.setTime(String.valueOf(Long.parseLong(item.getTime()) - 1));
}
notifyItemChanged(i , "time");
}
}
@Override
public void onFinish() {
}
}.start();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView tv_TimeRemained;
ImageView im_Team1, im_Team2;
public MyViewHolder(View view) {
super(view);
tv_TimeRemained = view.findViewById(R.id.tv_TimeRemained);
}
}
@Override
public int getItemCount() {
return mListenerList.size();
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.adapter_fixtures_list, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final String time = mListenerList.get(position).getTime();
if(Long.parseLong(time) > 0){
long FlashCount = Long.parseLong(time);
long millisUntilFinished = FlashCount * 1000;
long Days = TimeUnit.HOURS.toDays(TimeUnit.MILLISECONDS.toHours(millisUntilFinished));
long Hours = TimeUnit.MILLISECONDS.toHours(millisUntilFinished) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millisUntilFinished));
long Minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished));
long Seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished));
String format = "%1$02d";
holder.tv_TimeRemained.setText(String.format(format, Days) + ":" + String.format(format, Hours) + ":" + String.format(format, Minutes) + ":" + String.format(format, Seconds));
}
else{
holder.tv_TimeRemained.setText("Entry Over!");
}
}
}
I tried Runnable method also but same result.after trying all methods best result give me this.right now this method skipping frames every second i dont know is this right or not please check.
I appreciate for help.