您好我想使用SD卡中的图像绑定GridView,但不能在res / drawable文件夹中绑定? 下面是我使用res / drawable文件夹中的图像的代码 // //水稻
public static int[] mPictureIds_rice = {
R.drawable.chinese_fried_rice, R.drawable.nasi_goreng };
public static String[] mPrice_rice_detl = { "seafood \tRs. 725\nprawn \tRs. 675\nfish \tRs. 375\nchicken \tRs. 275\nvegetables\t Rs. 225\negg \tRs. 195",
"Rs. 375.00" };
public static String[] mPrice_rice = { "225.00", "375.00" };
public static String[] mName_rice_detl = { "chinese fried rice (chinese)",
"nasi goreng (indonesia)" };
public static String[] mName_rice = { "chinese fried rice",
"nasi goreng" };
public static String[] mName_rice_desc = {
"Wok tossed rice grains, assortment of vegetarian and non-vegetarian selection",
"Indonesian style fried rice with assorted seafood,meat and vegetable", };
public static int[] mVegNon_rice = { R.drawable.vegicon,
R.drawable.non_veg };
// //
** 及以下是我的gridview的代码 **
GridView gridview_rice = (GridView) findViewById(R.id.gridview_beverages);
gridview_rice.setAdapter(new ImageAdapter(this,
mPictureIds_rice, mName_rice, mPrice_rice));
gridview_rice.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
final int position, long id) {
Intent intent1 = new Intent(getApplicationContext(),
view_beverages_detail.class);
intent1.putExtra("position", position);
intent1.putExtra("Image", mPictureIds_rice);
intent1.putExtra("ImageName",mName_rice_detl);
intent1.putExtra("ImageNameShort",mName_rice);
intent1.putExtra("VegNonVegImage", mVegNon_rice);
intent1.putExtra("ItemDescription",mName_rice_desc);
intent1.putExtra("ItemPrice",mPrice_rice);
startActivity(intent1);
}
});
我从web服务获取图像并将它们放入文件夹下的android设备中,这就是为什么我想要 BIND GRIDVIEW来自设备中存储的图像?
答案 0 :(得分:0)
您可以使用绝对路径从SD卡中获取图像 例如,如果我将abc.png图像存储在xyz路径中,那么图像的绝对路径将是
String absPathOfImage = Environment.getExternalStorageDirectory()+"/xyz/"+abc.png
用int[] mPictureIds_rice
或数组列表
String[] mPictureIds_rice
public static String[] mPictureIds_rice = {
abspathOfImg1, R.drawable.nasi_goreng };
或
public static ArrayList<String> mPictureIds_rice = new ArrayList<String>();
在sd卡中存储后添加图像的绝对路径