문제

Hello I build an application with an imageswitcher and a button. When I press the button I need to set as wallpaper the current image displayed in the imageswitcher.

How can I get the full image path from the current displayed image? (like R.drawable.myimage)

I found getDisplayedChild() but is not doing what I need.

Here is my code:

 WallpaperManager myWallpaperManager
             = WallpaperManager.getInstance(getApplicationContext());
            try {
                int imageid = iSwitcher.getDisplayedChild();

            myWallpaperManager.setResource(imageid);
             alerta();
             System.out.println(pics[imageid]);
            } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
도움이 되었습니까?

해결책

Got it :)

If anyone need this I created a new int variable and assigned to it the image id of the clicked image from gallery.

iSwitcher.setImageResource(pics[arg2]);
foto = arg2;

and when I click my button I read "foto" var.

myWallpaperManager.setResource(pics[foto]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top