我有一個列表,它通過Android中的數據庫從另一個列表中添加項目。不過,我需要設置一個提醒每一個第三項,即3,6,9,12,等等。當我做這樣的如何在Android中的List中爲每個第三項設置提醒?
if(types.size() == 3 && types.size() == 6 && types.size() ==9)
我機應用意外關閉。以下是我的代碼。它的工作時,我只有一個號碼,但我需要它的所有第三個奇數。任何提示將是對我真正有價值的,謝謝
private List<AlcoholTypes> types = new ArrayList<AlcoholTypes>();
types = Database.getDataList(this);
if(types.size() == 3){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set title
alertDialogBuilder.setTitle("Water Reminder");
// set dialog message
alertDialogBuilder
.setMessage("Drink one glass of water !")
.setCancelable(false)
.setPositiveButton("Okay",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
dialog.cancel();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
謝謝你,它的工作:) – Sindre
請把它標記爲答案,如果你能給予好評它,這將有助於未來的觀衆。 –