Skip to content Skip to sidebar Skip to footer

Android - Store Drawable Ids In A Custom Xml File

In my app I'm using an xml file to store some data, and images are stored in the drawable folder. I would like to 'link' these to, meaning that each object in the xml file to refer

Solution 1:

you can try with only saving the name like "joe_pic" and can get this way

privatevoidshowImage() {
    Stringuri="drawable/icon";

    // int imageResource = R.drawable.icon;intimageResource= getResources().getIdentifier(uri, null, getPackageName());

    ImageViewimageView= (ImageView) findViewById(R.id.myImageView);
    Drawableimage= getResources().getDrawable(imageResource);
    imageView.setImageDrawable(image);
}

but if you have already added "R.drawable.joe_pic" complete can use String.split to get 3 rd string part

Post a Comment for "Android - Store Drawable Ids In A Custom Xml File"