0
我有一個擁有50+數據的回收站。在那裏我顯示時間戳差異。timstamp在recyclerview中不斷變化
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
try{
long mtime = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis())-TimeUnit.MILLISECONDS.toMinutes(Long.parseLong(time));
if (mtime<60){
holder.timestamp.setText(String.valueOf(mtime)+ " mins");
if (mtime==1)
holder.timestamp.setText(1+ " min");
else if (mtime<1){
holder.timestamp.setText("Just Now");
}
else
holder.timestamp.setText(mtime+ " mins");
}
else if (mtime>60 && mtime<1440){
if (mtime/60==1)
holder.timestamp.setText(String.valueOf(mtime/60)+ " hour");
else
holder.timestamp.setText(String.valueOf(mtime/60)+ " hours");
}
else if (mtime>1440&&mtime<10080){
if (mtime/1440==1)
holder.timestamp.setText(String.valueOf(mtime/1440)+ " day");
else
holder.timestamp.setText(String.valueOf(mtime/1440)+ " days");
}else if(mtime>10080&&mtime<3679200){
if (mtime/10080==1)
holder.timestamp.setText(String.valueOf(mtime/10080)+ " week");
else
holder.timestamp.setText(String.valueOf(mtime/10080)+ " weeks");
}else if(mtime>3679200){
if (mtime/3679200==1)
holder.timestamp.setText(String.valueOf(mtime/3679200)+ " year");
else
holder.timestamp.setText(String.valueOf(mtime/3679200)+ " years");
}
}catch (Exception e){
}
h.postDelayed(this,1000);
}
},1000);
它工作正常。但是當我滾動回收站查看時,它會不斷更改其他回收站查看項目的時間戳。
您可能希望將'System.currentTimeMillis()'作爲循環外部的值存儲起來 –
它仍在重複其他值@ScaryWombat – Bucky