【发布时间】:2011-02-14 20:51:40
【问题描述】:
我正在开发一个简单的应用程序,其中我在列表的每一行中显示一个复选框和一个文本,但是当我选择或选中一个复选框时,我的列表视图中的一些其他复选框会自动选中。 我在谷歌上做了很多,但找不到解决这个问题的方法...... 请帮帮我....
提前谢谢....
public void checkevent(View v) throws ParseException
{
lv=(ListView)v.getParent().getParent();
int i=lv.getPositionForView(v);
Object o = lv.getItemAtPosition(i);
String item= o.toString();
int q=item.indexOf("-",0);
String alarm_date=new_date+" "+item.substring(0,q);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date rdate = (Date)formatter.parse(alarm_date);
set_prog=item.substring(q+1,item.length())+" on "+item.substring(0,q);
if(((CompoundButton) v).isChecked())
{
if(rdate.getTime()>=new Date().getTime())
{
if(program_reminder_main.contains((alarm_date+"--"+item.substring(q+1,item.length()))))
{
Toast.makeText(this,"You have already selected this one", Toast.LENGTH_LONG).show();
((CompoundButton) v).setChecked(false);
}
else {
program_reminder_main+=("~"+alarm_date+"--"+item.substring(q+1,item.length()));
}
//To call the Alarm service Class at respective time
Toast.makeText(this, "Alarm Set For"+" "+item.substring(q+1,item.length())+" on "+item.substring(0,q), Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(MainClass.this, MyAlarmService_Movie.class);
pendingIntent = PendingIntent.getService(MainClass.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,rdate.getTime()-30000,pendingIntent);
}
else {
((CompoundButton) v).setChecked(false);
Toast.makeText(MainClass.this, "Alarm can't be set Before to crrent time", Toast.LENGTH_LONG).show();
}
}
else if(!((CompoundButton) v).isChecked()){
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
Toast.makeText(MainClass.this, "Reset Alarm", Toast.LENGTH_LONG).show();
}
}
忽略多余的东西...只关注复选框的代码...以及您的信息。我已经在复选框的属性中设置了上述方法...
【问题讨论】:
标签: android