我正在做一个 Android 应用程序,我必须在我的数据库中的列表视图记录中显示。但是,我调用了可绘制对象并将其分配给数组的照片。如何使用 SimpleCursorAdapter 在 ImageView 上显示照片?
这是我到目前为止所尝试的:
static final int[] imgs = {
R.drawable.dinaretreat, // 0
R.drawable.cobterrace, // 1
R.drawable.ventassostreet, // 2
R.drawable.summerhillblvddrouin, // 3
R.drawable.todmanstreetdrouin, // 4
R.drawable.aqueductroad // 5
};
private DBHelper dbHelper;
SimpleCursorAdapter dataAdapter;
Cursor cursor;
Button back, filter;
TextView highest, lowest, location;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewhouseandland);
initControls();
displayRecords();
}
private void displayRecords() {
// TODO displayRecords
// TODO CheckDBConnection
checkDatabaseConnection();
// TODO
cursor = dbHelper.getAllHouses();
// The desired columns to be bound
String[] columns = new String[] {
DBHelper.KEY_HOUSE,
DBHelper.KEY_PRICE
};
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.image,
R.id.text1,
R.id.text2
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.listrow,
cursor,
columns,
to,
0);
lv.setAdapter(dataAdapter);
}
我很难在我的列表视图上显示图像。有任何想法吗?我很乐意感谢您的帮助。谢谢。