2016-07-16 1 views
0

Я настроил listview событий с их датами. Если использование выбирает определенный элемент в списке, тогда моя программа спросит, хочет ли пользователь напоминать об этом событии. У меня возникла проблема с циклом событий. Например, для позиции 1, если я установил напоминание в 14:15 и для позиции 2, я установил напоминание в 2:30. Уведомление о втором списке будет отображаться с игнорированием первого. Я хочу, чтобы оба этих уведомления показывались в соответствующее время.Android list view looping

Может кто-нибудь узнать и помочь мне в том, как зацикливать список, чтобы я мог установить напоминания о любом элементе в списке.

Пожалуйста, проверьте метод 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;

}
 
 

}
введите код здесь»

ответ

0

Проблема лежит в этой строке:

pendingIntent = PendingIntent.getBroadcast(Product.this, 0,myIntent,0); 

Второй параметр означает requestCode, и он должен быть уникальным для различных сигналов тревоги. Вы устанавливаете его на 0 каждый раз, из-за чего предыдущий аварийный сигнал становится переопределенным.

+0

Я изменил второй параметр второго оператора if на 1, но теперь первый работает отлично, но второй аварийный сигнал даже не показывает – timmy24565

+0

Вам нужно сохранить его уникальным для каждого сигнала. –

+0

не могли бы вы объяснить об этом подробнее. Благодарю. Первый появляется, а второй появляется, но не отдельно. Когда вызывается второй сигнал тревоги, первый из них все еще переопределен – timmy24565