I am working in an Wedding App where I am maintaining a ListView of feeds.
The First element of my Feed Screen ListView is having a TIMER for the CURRENT DATE to the WEDDING DATE.
As I have taken the TIMER
in a ListView
, it getting hard to update the text of the TextView
in onTick()
method.
Wedding time is only visible in the first element of the list view.
_time = new CountDownTimer(WeddingTimeinMiliSec, 5000) {
String showDate;
long subtractvalue = 1000;
Calendar currentTime = Calendar.getInstance();
public void onTick(long millisUntilFinished) {
long diff = Day.getTimeInMillis() - currentTime.getTimeInMillis();
diff-=subtractvalue;
StringBuffer text = new StringBuffer("");
if (diff > DAY) {
//showDate = showDate+""+(diff / DAY)+("days ");
final long dif = diff;
if(holder!=null && holder._dayRespTextView!=null){
runOnUiThread(new Runnable() {
@Override
public void run() {
holder._dayRespTextView.setText(String.valueOf((dif / DAY)));
}
});
}
text.append(diff / DAY).append(" days ");
diff %= DAY;
}
if (diff > HOUR) {
// showDate = showDate+""+(diff / HOUR)+("hours ");
final long dif = diff;
if(holder!=null && holder._hoursRespTextView!=null){
runOnUiThread(new Runnable() {
public void run() {
holder._hoursRespTextView.setText(String.valueOf((dif / HOUR)));
}
});
}
text.append(diff / HOUR).append(" hours ");
diff %= HOUR;
}
if (diff > MINUTE) {
// showDate = showDate+""+(diff / MINUTE)+("minutes ");
final long dif = diff;
if(holder!=null && holder._minRespTextView!=null){
runOnUiThread(new Runnable() {
public void run() {
holder._minRespTextView.setText(String.valueOf((dif / MINUTE)));
}
});
}
text.append(diff / MINUTE).append(" minutes ");
diff %= MINUTE;
}
if (diff > SECOND) {
// showDate = showDate+""+(diff / SECOND)+("seconds ");
final long dif = diff;
if(holder!=null && holder._secRespTextView!=null){
runOnUiThread(new Runnable() {
public void run() {
holder._secRespTextView.setText(String.valueOf((dif / SECOND)));
}
});
}
text.append(diff / SECOND).append(" seconds ");
diff %= SECOND;
}
/*_tvTime.setText(""+WeddingTime);*/
showDate="";
subtractvalue+=1000;
notifyDataSetChanged();
}
public void onFinish() {
}
}.start();
This is my CountDownTimer code that I am using inside the CONSTRUCTOR of my ListView ADAPTER.
How can I update the text of the TextViews in the ListView's first element on onTick event. Please suggest me.
try this..