我有自定義的事件與他們的日期列表視圖。如果該用途選擇列表上的特定項目,則我的程序將詢問用戶是否想要提醒該事件。我遇到了循環事件的問題。例如,對於位置1,如果我將提醒設置爲下午2:15和位置2,則會將提醒設置爲2:30。第二個列表的通知將會出現,而忽略第一個列表。我希望這兩個通知都能在各自的時間顯示。Android列表視圖循環
有人可以找出並幫助我如何循環列表,所以我可以設置列表上的任何項目的提醒。
請檢查OnClickResponse()方法,這是我創建鬧鐘的地方。
'public class Product extends AppCompatActivity implements View.OnClickListener {
private List<list> myList = new ArrayList<list>();
private PendingIntent pendingIntent;
private void fill_ListView() {
在此行中輸入代碼在這裏」
ArrayAdapter<list> listArrayAdapter = new myListAdapter();
ListView list = (ListView) findViewById(R.id.product_View);
list.setAdapter(listArrayAdapter);
} private void clickResponse() {
ListView l = (ListView) findViewById(R.id.product_View);
if(l!=null){
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View viewClicked,
final int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(
Product.this);
alert.setTitle("Reminder!!");
alert.setMessage("Do you want to be reminded of the expiry date of this product?」);
alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Calendar calendar = Calendar.getInstance(); // checking if first item is clicked then a reminder will be set for some date
if(position==0){
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.DAY_OF_MONTH, 16);
calendar.set(Calendar.HOUR_OF_DAY, 04);
calendar.set(Calendar.MINUTE, 38);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM,Calendar.AM);
Intent myIntent = new Intent(Product.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(Product.this, 0,myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
} if(position==1){
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.DAY_OF_MONTH, 16);
calendar.set(Calendar.HOUR_OF_DAY, 04);
calendar.set(Calendar.MINUTE, 39);
calendar.set(Calendar.SECOND, 40);
calendar.set(Calendar.AM_PM,Calendar.AM);
Intent myIntent = new Intent(Product.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(Product.this, 0,myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
}
dialog.dismiss();
}
});
alert.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
});
}
}
private class myListAdapter extends ArrayAdapter<list> {
public myListAdapter() {
// what objects are going in there and how are they going to look
super(Product.this, R.layout.custom_layout, myList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (itemView == null) {
itemView = getLayoutInflater().inflate(R.layout.custom_layout, parent, false);
}
list current_list = myList.get(position);
ImageView imageView = (ImageView) itemView.findViewById(R.id.id_image);
imageView.setImageResource(current_list.getIconId());
// getting the title of the event
TextView titleTxt = (TextView) itemView.findViewById(R.id.id_event);
titleTxt.setText(current_list.getName());
// getting the description
//
TextView desp = (TextView) itemView.findViewById(R.id.id_desp);
// desp.setText(current_list.getDetails());
EditText text = (EditText)itemView.findViewById(R.id.id_desp);
text.setText(current_list.getDetails());
TextView date = (TextView) itemView.findViewById(R.id.id_date);
date.setText(current_list.getDate());
return itemView;
}
}
我將第二個if語句的第二個參數更改爲1,但現在第一個正常工作,但第二個鬧鐘甚至沒有顯示 – timmy24565
您需要爲每個鬧鐘保持唯一。 –
請你解釋一下。謝謝。第一個出現,第二個出現,但沒有分開。當第二次報警被調用時,第一個報警仍然被覆蓋 – timmy24565