我正在開發一個簡單的應用程序,其中我在列表的每一行中顯示覆選框和文本,但是當我選擇或檢查一個複選框時我的列表視圖內的其他複選框會自動檢查。 我已經做了很多谷歌上,無法找到一個方法來解決這個問題... 請幫我....關於列表視圖內的複選框的選中狀態
Thanx提前....
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();
}
}
忽略額外事情......只關注複選框的代碼......以及您的信息。我已經設置在複選框的屬性上面的方法...
謝謝你的建議,但讓我給我的代碼給你... – user595226 2011-02-14 12:46:21