我需要验证用户每天只使用Android中的计时器或闹钟管理器选择一项。有没有更好的方法来设计它,因此很容易检查用户是否每天不会获得多个项目。我列出了列表视图中显示的十个项目。用户从列表中获取项目。他应该只得到一件物品。如果他再次尝试,他应该每天只提醒一件物品。
公共类MainActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Effects.getInstance().init(this);
ListView lv = (ListView) findViewById(R.id.listView);
List<ItemDetail> itemList = createItems(10);
// Load animation
final Animation anim = AnimationUtils.loadAnimation(this, R.anim.fade_anim);
final ArrayAdapter<ItemDetail> aAdpt = new ArrayAdapter<ItemDetail>(this, android.R.layout.simple_list_item_1,
itemList);
lv.setAdapter(aAdpt);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, final View view, final int position, long id) {
MediaPlayer mPlayer = MediaPlayer.create(MainActivity.this, R.raw.gum_bubble_pop);
mPlayer.start();
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
long now = System.currentTimeMillis();
long lastCheckedMillis = 0;
long diffMillis = now - lastCheckedMillis;
if( diffMillis >= (3600000 * 24) ) {
// store now (i.e. in shared prefs)
// do the check
} else {
// too early
}
if(aAdpt.getCount()==9) {
Toast.makeText(MainActivity.this, "You can get only one gift per day "+now, Toast.LENGTH_LONG).show();
}
else {
ItemDetail item = aAdpt.getItem(position);
aAdpt.remove(item);
}
}
});
view.startAnimation(anim);
}
});
}
private List<ItemDetail> createItems(int size) {
List<ItemDetail> result = new ArrayList<ItemDetail>();
for (int i = 0; i < size; i++) {
ItemDetail item = new ItemDetail(i, "Gift " + (i + 1));
result.add(item);
}
return result;
}
}
答案 0 :(得分:0)
if(view.store.getCount()) view.bufferedRenderer.scrollTo(index);
作为每30分钟一次的触发循环,此代码将检查时间是否在午夜和午夜之间。因此,将此代码放入触发器中,并在if内部编写您希望执行的代码,如果自上次循环运行以来一天发生了更改。