您可以通過這個下面的代碼得到壓延ID:
String projection[] = {"_id", "calendar_displayName"};
Uri calendars;
calendars = Uri.parse("content://com.android.calendar/calendars");
ContentResolver contentResolver = c.getContentResolver();
Cursor managedCursor = contentResolver.query(calendars, projection, null, null, null);
if (managedCursor.moveToFirst()){
m_calendars = new MyCalendar[managedCursor.getCount()];
String calName;
String calID;
int cont= 0;
int nameCol = managedCursor.getColumnIndex(projection[1]);
int idCol = managedCursor.getColumnIndex(projection[0]);
do {
calName = managedCursor.getString(nameCol);
calID = managedCursor.getString(idCol);
m_calendars[cont] = new MyCalendar(calName, calID);
cont++;
} while(managedCursor.moveToNext());
managedCursor.close();
}
所以,你可以在運行時得到壓延Id和使用它。你不需要硬編碼的1或3列ID。
你能告訴我MyCalendar []是什麼嗎? @chandrakant – droidman
我的方法將採取返回類型的日曆,爲什麼我採取了,但你不需要我編輯我的代碼給你 –