我使用Simple Cursor Adapter创建了一个列表视图,在该适配器中,我获取了Sqlite列名,现在我想从Drawable文件夹中添加图像到同一个适配器中。如何做到这一点?请提供您的建议和想法,谢谢。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
final int[] imageResource =new int[] {R.drawable.juice, R.drawable.medicinebowl, R.drawable.kam};
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ListView) findViewById(R.id.listView);
dbHelper = new SqlLiteDbHelper(this);
try {
dbHelper.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteDatabase = dbHelper.getReadableDatabase();
cursor = dbHelper.gettitles(sqLiteDatabase);
String[] from = new String[]{dbHelper.TITLE, String.valueOf(circle)};
int[] to = new int[]{R.id.title,R.id.circle};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.title_row, cursor, from, to);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
Drwable int[] imageResource = {R.drawable.juice, R.drawable.medicinebowl, R.drawable.kam};
中的图像,并将其附加到我的适配器中,如String[] from = new String[]{dbHelper.TITLE, String.valueOf(imageResource)};
@Tony - vasanth