我所拥有的是用于列表视图的游标适配器。在此适配器中,我们有以下代码。该项目是一个ImageView,我正在尝试使其可见并将其设置为来自数据库的值中的图像名称。你可以从我的logcat中看到它为null并且当它被填充时它仍然失败。我假设我需要将字符串转换为位图对象或drawable。任何人吗?
Log cat:
06-21 09:32:38.020: I/PROJECTCARUSO(10061): is_stamp: observation_4
06-21 09:32:38.020: I/PROJECTCARUSO(10061): is_stamp2: observation_4
06-21 09:32:38.020: I/System.out(10061): resolveUri failed on bad bitmap uri: observation_4
06-21 09:32:38.101: I/PROJECTCARUSO(10061): is_stamp: null
06-21 09:32:38.101: I/PROJECTCARUSO(10061): is_stamp3: null
06-21 09:32:38.101: I/System.out(10061): resolveUri failed on bad bitmap uri:
if (columnIndex == cursor.getColumnIndex(StatusData.KEY_CHARTING_STAMPS)) {
String is_stamp = cursor.getString(columnIndex);
Log.i("PROJECTCARUSO", "is_stamp0: " + is_stamp);
if (is_stamp != null) {
if (is_stamp.equalsIgnoreCase("")){
// set the visibility of the view to GONE
Log.i("PROJECTCARUSO", "is_stamp1: " + is_stamp);
view.setVisibility(View.INVISIBLE);
}else {
Log.i("PROJECTCARUSO", "is_stamp2: " + is_stamp);
view.setVisibility(View.VISIBLE);
}
} else {
Log.i("PROJECTCARUSO", "is_stamp3: " + is_stamp);
view.setVisibility(View.INVISIBLE);
}
答案 0 :(得分:0)
Drawable is_stamp_draw = getResources().getDrawable(getResources().getIdentifier("drawable/" + is_stamp, null, getActivity().getPackageName()));
view.setBackground(is_stamp_draw);