我有以下代码:
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.listitem_exercise_image) {
String image_1 = cursor.getString(columnIndex);
Log.d("MyApp", "image_1 = " + image_1);
int resourceId = getResources().getIdentifier(image_1 , "drawable", getPackageName());
Log.d("MyApp", "image_1 id = " + String.valueOf(resourceId));
return true;
}
return false;
}
});
现在,在日志中,它显示了我的Log.d
:
12-30 23:34:04.995: D/MyApp(8354): image_1 = abdominal_4_point_drawing_in_1.png
12-30 23:34:05.015: D/MyApp(8354): image_1 id = 0
12-30 23:34:05.165: D/MyApp(8354): image_1 = alternate_hammer_curl_1.png
12-30 23:34:05.195: D/MyApp(8354): image_1 id = 0
12-30 23:34:05.325: D/MyApp(8354): image_1 = alternate_incline_dumbbell_curl_1.png
12-30 23:34:05.335: D/MyApp(8354): image_1 id = 0
现在所有这些 .png 文件都存在于“drawable”文件夹中。他们肯定在那个文件夹里。我知道这一点,因为我是将它们放入该文件夹的人,而且我也只是仔细检查过。我还运行了 Project Clean。
那么为什么每个资源 ID 都为 0 呢?