Skip to content Skip to sidebar Skip to footer

Storing Images In Drawable Folder And Getting The Image To Load By Using The Imagepath In Database

I am wondering how to get the imagePath of the image stored in the drawable folder in eclipse. The imagePath is to be stored in SQLite Database. So now I am wondering how do I retr

Solution 1:

Stringpath= getResources().getString(R.drawable.icon);

Solution 2:

any image resource should be placed in drawable so its not about path you just need the image name to be saved in database related to some entity and the by getting it from database you can get the image resource through the code below

Bitmapimage= BitmapFactory.decodeResource(getResources(), getResources().getIdentifier( "imagename" , "drawable", getPackageName()));

Update:

as now from your code according to question you were trying to get images through name(path) means instead of Integer array Integer[] imageIDs = {R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4}; you want image resources to be pointed through database so to do this first you have to get all image names(the names same as the name of images in drawable folder) you saved in column of a table in database once you got the names through query then instead of reference through Integer array just the names from database will allow you to access the image resources from drawables, im supposing that image names are stored by following way ArrayList<String> imageNames = new ArrayList<String>(); //hence in the while loop of cursor during retriving values from cursor imageNames.add(cursor.getString(columnIndex));

so the updated code will like below where

@Overridepublic View getView(int position, View convertView ,ViewGroup parent)
        {
            ImageViewimageView=newImageView(context);
            imageView.setImageResource(getResources().getIdentifier(imageNames.get(position), "drawable", this.getPackageName()));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageView.setLayoutParams(newGallery.LayoutParams(150, 120));
            imageView.setBackgroundResource(itemBackground);


            return imageView;
        }

if you still confused then there is no other solution i think i can do

Post a Comment for "Storing Images In Drawable Folder And Getting The Image To Load By Using The Imagepath In Database"