java - 通用图像加载器 : how to catch id of browsed image?

标签 java android universal-image-loader

我正在向 ImagePagerActivity 添加一个按钮,以将图像设置为手机的背景。 功能本身运行良好(如果我设置 R.drawable.icon,我可以将应用程序的图标设置为 bg)。

问题是我完全不知道如何获取图像 ID,以便人们可以将他们当前正在浏览的图像设置为 bg。我尝试了很多东西,但没有任何效果。

例如,R.id.image发送“false”,R.layout.item_pager_image发送XML路径(好吧,这是正常的,只是为了测试), 等等...我真的不知道我可以用什么值(value)说“嘿,把我正在看的这张照片作为我的新手机背景”。

这是我在 ImagePagerActivity.java 中最后一个 之前使用的代码。 (是的,壁纸代码被注释了,我打印调试值)

感谢您的帮助!

    public void onWallpaperClick(View view) {
        openMyDialog(null);
    }   

    public void openMyDialog(View view) {
        showDialog(10);
    }

    //@Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case 10:
            // Create our AlertDialog
            Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Définir cette photo comme fond d'écran de votre appareil ?")
                    .setCancelable(true)
                    .setPositiveButton("Oui",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // Ends the activity
                                    //HomeActivity.this.finish();
                                    WallpaperManager myWallpaperManager
                                    = WallpaperManager.getInstance(getApplicationContext());
                                   //try {
                                   //myWallpaperManager.setResource(R.id.image);
                                   //} catch (IOException e) {
                                   // e.printStackTrace();
                                  // }
                                    Toast.makeText(getApplicationContext(),
                                            R.drawable.icon,
                                            Toast.LENGTH_SHORT).show();

                                }
                            })
                    .setNegativeButton("Non",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    Toast.makeText(getApplicationContext(),
                                            "Ok !",
                                            Toast.LENGTH_SHORT).show();
                                }
                            });

            return builder.create();
        }
        return super.onCreateDialog(id);
    }   

最佳答案

如果这些方法在显示器的同一个 Activity 中,你可以试试这个:

在 ImageLoadingListener::OnLoadingComplete(Bitmap bitmap) 方法中,您可以加载位图,因此使用属性处理位图。

public class myActivity {
    Bitmap current_bitmap;
{...}
    imageLoader.displayImage(images[position], imageView, options,
        new ImageLoadingListener() {
            @Override
            public void onLoadingComplete(Bitmap loadedImage) {
                current_bitmap = loadedImage;
            }
            {...}
        }
}

你可以让它与 WallpaperManager 一起使用

WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
  myWallpaperManager.setBitmap(current_bitmap);
} catch (IOException e) {
  e.printStackTrace();
}

关于java - 通用图像加载器 : how to catch id of browsed image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13192326/

相关文章:

java - 数组的 toString 方法

android - 如何通过您的应用程序运行 traceroute 命令?

android - 从 Intent.ACTION_GET_CONTENT 到文件的 URI

android - 通用图像加载器 - 如何将第二个图像加载到 ImageView 中?

java - 在 imageLoader 的子类上调用方法

android: Universal Image Loader 从字符串数组中获取可绘制对象

java - 将 ExecutorService 与要执行的任务树一起使用

java - 为什么我的程序无法识别文本文件中的所有名称?

电子邮件域的 Java RegEx

java - 通过 CustomTab 或 Chrome 发布数据