我在listview中显示表内容时遇到了一些问题。
我有这个方法:
public ArrayList<category> getAllCategories()
{
ArrayList<category> categories = new ArrayList<category>();
String selectQuery = "SELECT * FROM " + category.TABLE;
Log.e("DBHelper",selectQuery);
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery,null);
if(c.moveToFirst())
{
do{
category cat = new category();
cat.set_id(c.getInt(c.getColumnIndex(category.KEY_ID)));
cat.set_category_name(c.getString(c.getColumnIndex(category.KEY_CATEGORY_NAME)));
categories.add(cat);
} while(c.moveToNext());
}
return categories;
}
我想在mainactivity.java中调用此方法并在listview中查看结果,但我不知道为什么此代码不起作用:
categoryRepo categoryRepo = new categoryRepo(this);
ArrayAdapter<String> adapter;
ListView list;
list = (ListView) findViewById(R.id.listView1);
ArrayList<category> categories = categoryRepo.getAllCategories();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,categories); // --here I get an error, cannot resolve constructor
list.setAdapter(adapter);