我有用android編寫的小應用程序。Android - 可繪製路徑
從SQLite數據庫中,我提取了一些類別和圖標名稱,如(酒店,公寓等)。我在drawable
文件夾中的所有圖像示例。
現在我正在嘗試閱讀這些圖像並將它們顯示在列表中,但我遇到了可繪製路徑的問題。錯誤總是:open failed: ENOENT (No such file or directory)
。
下面是代碼示例:
@Override
public View getView(int position, View view, ViewGroup parent)
{
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.category_list_item, null, true);
Uri otherPath = Uri.parse("android.resource://"+getContext().getPackageName()+"/drawable/");
String drawable_path = otherPath.toString();
Toast.makeText(getContext(), drawable_path, Toast.LENGTH_LONG).show();
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
TextView categoryID = (TextView) rowView.findViewById(R.id.category_id);
txtTitle.setText(items.get(position));
imageView.setImageDrawable(Drawable.createFromPath(drawable_path+imageIds.get(position)+"\""));
categoryID.setText(category_ids.get(position));
return rowView;
}
你能告訴我一些如何通過查找來實現嗎? –