Android 使用外部图像绑定 GridView?

发布于 2024-11-17 01:00:14 字数 2287 浏览 4 评论 0原文

您好,我想将 GridView 与 sd 卡中的图像绑定,但不在 res/drawable 文件夹中? 下面是我使用 res/drawable 文件夹中的图像的代码 //RICE//

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);
            }
        });

我从网络服务获取图像并将它们放入 Android 设备的文件夹下,这就是原因我想要从设备中存储的图像绑定 GRIDVIEW?

Hi i want to Bind GridView with images from the sd-card but not in the res/drawable folder?
below is code where i am using images from res/drawable folder
//RICE//

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 };
    // //

**and below is the code for my 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);
            }
        });

I am getting images from the webservice and putting them into android device under folder thats the reason why i want BIND GRIDVIEW FROM IMAGES STORED IN THE DEVICE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2024-11-24 01:00:14

您可以使用绝对路径从 SD 卡获取图像
例如,如果我将 abc.png 图像存储在 xyz 路径中,则图像的绝对路径将

String absPathOfImage = Environment.getExternalStorageDirectory()+"/xyz/"+abc.png

替换为 String[] mPictureIds_rice 或数组列表

public static String[] mPictureIds_rice = {
            abspathOfImg1, R.drawable.nasi_goreng };

public static ArrayList<String> mPictureIds_rice = new ArrayList<String>();

添加图片存储到sd卡后的绝对路径

you can get the images from the sd card using their absolutepath
example if i store abc.png image in xyz path then the absolute path of the image will be

String absPathOfImage = Environment.getExternalStorageDirectory()+"/xyz/"+abc.png

replace int[] mPictureIds_rice either with String[] mPictureIds_rice or with array list

public static String[] mPictureIds_rice = {
            abspathOfImg1, R.drawable.nasi_goreng };

or

public static ArrayList<String> mPictureIds_rice = new ArrayList<String>();

add the absolute path of image after storing in sd card

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文