Question

I want to allow the App's user to select from Drawable folder an image and change the ImageButton's image.
In my App I put in Drawable folder some pictures.

It's possible?

My idea is :
1) There is an ImageButton
2) User clic on setOnLongClickListener
3) Choose the image from Drawable folder and customize icon.

Thanks for all!

Was it helpful?

Solution

Please post some code, anyway this is a trivial solution:

//Execute on onItemLongClick
public void setSelectedDrawable(String imageResName, int selectedDrawableId) {

    Resources resources = context.getResources();
    Drawable drawable = resources.getDrawable(selectedDrawableId);
    if(drawable == null) resources.getIdentifier(imageResName, "drawable", "<package name>");           
    mImageButton.setImageDrawable(drawable);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top