本文实例为大家分享了Android ListView列表实现倒计时的具体代码,供大家参考,具体内容如下
效果图:
1. Activity
package com.s296267833.ybs.activity.firstPage.timedown;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import com.s296267833.ybs.R;
import java.util.ArrayList;
import java.util.List;
/**
* ListView列表实现倒计时
* */
public class TimeDownActivity extends AppCompatActivity {
private TimeDownLvAdapter mAdapter;
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_down);
mListView= findViewById(R.id.lv_time_down);
setAdapter();
}
/**
* 设置适配器
* */
private void setAdapter() {
mAdapter = new TimeDownLvAdapter(this,getTimerItemList());
mListView.setAdapter(mAdapter);
}
/**
* 设置倒计时的数据
* */
public static List getTimerItemList() {
List lstTimeDownItems = new ArrayList<>();
lstTimeDownItems.add(new TimeDownItem("A千万种心动", System.currentTimeMillis() + 11 * 1000));
lstTimeDownItems.add(new TimeDownItem("B千万种心动", System.currentTimeMillis() + 22 * 1000));
lstTimeDownItems.add(new TimeDownItem("C千万种心动", System.currentTimeMillis() + 26 * 1000));
lstTimeDownItems.add(new TimeDownItem("D千万种心动", System.currentTimeMillis() + 33 * 1000));
lstTimeDownItems.add(new TimeDownItem("E千万种心动", System.currentTimeMillis() + 24 * 1000));
lstTimeDownItems.add(new TimeDownItem("F千万种心动", System.currentTimeMillis() + 98 * 1000));
lstTimeDownItems.add(new TimeDownItem("G千万种心动", System.currentTimeMillis() + 14 * 1000));
lstTimeDownItems.add(new TimeDownItem("H千万种心动", System.currentTimeMillis() + 36 * 1000));
lstTimeDownItems.add(new TimeDownItem("I千万种心动", System.currentTimeMillis() + 58 * 1000));
lstTimeDownItems.add(ne