झिलमिलाते मैं दिखाने के लिए कितना समय मेरी RecyclerView
की प्रत्येक कोशिका के अंदर छोड़ दिया है ... उस के लिए मैं प्रत्येक के लिए एक उलटी गिनती टाइमर का इस्तेमाल किया है चाहता हूँ कारण बनता है। प्रत्येक पंक्ति में मैं एक काउंटर शुरू करने और onTick()
प्रबंधन ... सब काम करता है के रूप में उम्मीद ... मैं प्रत्येक पंक्ति के लिए एक टाइमर टिक मिल गया है और मेरे सेल भी अपडेट कर रहा है, लेकिन मेरे सेल अब झिलमिलाते है .... और यह पागल हो जाता है जब मैं स्क्रॉल करता हूं।Recyclerview
यहाँ मेरी एडाप्टर है ...
if (product.getProductType().equalsIgnoreCase("Auction Product")) {
isAuction=true;
viewHolder.img_product_type.setImageResource(R.drawable.bid);
viewHolder.txt_timeleft.setVisibility(View.VISIBLE);
start_countDown(product.getStart(),product.getStop(),viewHolder.txt_timeleft);
}
काउंटर कोड के रूप में नीचे है ....
private void start_countDown(String start, String stop, final TextView txt_timeleft) {
try {
//Log.e("hetal",start+"....."+stop);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar start_date = Calendar.getInstance();
start_date.setTime(format.parse(start));
Calendar end_date = Calendar.getInstance();
end_date.setTime(format.parse(stop));
final Calendar today = Calendar.getInstance();
CountDownTimer timer;
txt_timeleft.setTextColor(Color.DKGRAY);
if(today.before(start_date)){
txt_timeleft.setTextColor(context.getResources().getColor(R.color.red));
txt_timeleft.setText(context.getString(R.string.auction_not_start));
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
txt_timeleft.startAnimation(anim);
return;
}
if (!today.before(end_date)) {
txt_timeleft.setTextColor(context.getResources().getColor(R.color.red));
txt_timeleft.setText(context.getString(R.string.time_out));
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
txt_timeleft.startAnimation(anim);
return;
}
timer = new CountDownTimer(end_date.getTimeInMillis(), 1000) {
@Override
public void onTick(long millisUntilFinished) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millisUntilFinished);
long diff = calendar.getTimeInMillis() - today.getTimeInMillis();
long seconds = diff/1000 % 60;
long minutes = diff/(60 * 1000) % 60;
long hours = diff/(60 * 60 * 1000) % 24;
//long days = (int) diff/(24 * 60 * 60 * 1000);
long days = TimeUnit.MILLISECONDS.toDays(diff);
String left = "";
if (days > 0)
left += days + " " + context.getString(R.string.txt_day) + " ,";
if (hours > 0)
left += hours + " " + context.getString(R.string.txt_hour) + " ,";
if (minutes > 0)
left += minutes + " " + context.getString(R.string.txt_minute) + " ,";
left += seconds + " " + context.getString(R.string.txt_second);
final String finalLeft = left;
if (finalLeft.equals("0") || finalLeft.contains("-")) {
txt_timeleft.setText(context.getString(R.string.time_out));
txt_timeleft.setTextColor(context.getResources().getColor(R.color.red));
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
txt_timeleft.startAnimation(anim);
} else
txt_timeleft.setText(finalLeft);
}
@Override
public void onFinish() {
}
};
timer.start();
}catch (Exception ex){
ex.printStackTrace();
}
}
क्योंकि जब आप स्क्रॉल करें, यह फिर से फोन उन तरीकों और टाइमर वर्ग की नई वस्तुओं को बनाता है। –
@HammadTariqSahi इसके लिए किसी भी समाधान ... क्योंकि प्रत्येक कोशिका में मैं अलग समय तो मैं onBindViewHolder –