1
我知道這個問題之前已經被多次詢問過,但沒有一個解決方案適用於我。這是我的代碼:Android無法解析構造函數ArrayAdapter
public class reminderDAO extends dbManager{
public reminderDAO(Context context) {
super(context);
}
// Adding new reminder
public void addReminder(Reminder reminder) {
//dbm.gettingWritable(values);
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(getKEY_DATE(), reminder.getReminderDate());
values.put(getKEY_TITLE(), reminder.getReminderTitle());
values.put(getKEY_DESC(), reminder.getReminderDescription());
values.put(getKEY_TIME(), reminder.getReminderTime());
// Inserting Row
db.insert(getDATABASE_TABLE(), null, values);
db.close(); // Closing database connection
}
public List<Reminder> getAllReminders(ListView lv) {
ArrayList<Reminder> reminderList = new ArrayList<Reminder>();
// Select All Query
String selectQuery = "SELECT * FROM " + getDATABASE_TABLE();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
MainActivity ma = new MainActivity();
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Reminder r = new Reminder();
r.setReminderDate(cursor.getString(0));
r.setReminderTitle(cursor.getString(1));
r.setReminderDescription(cursor.getString(2));
r.setReminderTime(cursor.getString(3));
// Adding reminder to list
reminderList.add(r);
} while (cursor.moveToNext());
}
ArrayAdapter<Reminder> arrayAdapter = new ArrayAdapter<Reminder>(
this,
android.R.layout.simple_list_item_1,
reminderList);
lv.setAdapter(arrayAdapter);
// return reminder list
return reminderList;
}
}
我有一種感覺,它是與「本」一個ArrayAdapter裏面做。我嘗試過getActivity(),this.getActivity(),reminderDAO.this.getActivity(),MainActivity.this和reminderDAO.this。
任何人都有解決方案?
只是一個側面節點:取有關Java編碼規範護理。類名始終應該啓動UpperCase:ReminderDao和DbManager是一個更好的命名。 –
好的,謝謝,注意。任何關於我得到的錯誤的想法? –
您是否嘗試過「上下文」? – Emil