English 中文(简体)
1. 从阵列的参考文献中确定形象。
原标题:Set imageview from array reference?

我只字不提。 我愿在上建立<代码>>ImageView,在一系列<代码>上的图像上打上<<<>Drawables。 我愿对<代码>ImageView的图像,可以通过查阅mImages[position]检索。

Here is a brief explanation (complete explanation below): In short- I need a way to pass an image from my main activity to a dialog then on Cancel dismiss the dialog and on confirm set the system wallpaper (to the image passed from the main activity) then finish(); the activity.

此处作完整解释:

用户名单见Gallery,高于Gallery,这表明对上重点的图像进行了较大的审查。 彩虹/代码。

在<代码>Gallery上展示的图像使用:

        // setup wallpaper array
private void findWallpapers() {
    mThumbs = new ArrayList<Integer>(24);
    mImages = new ArrayList<Integer>(24);

    final Resources resources = getResources();
    final String packageName = getApplication().getPackageName();

    addWallpapers(resources, packageName, R.array.wallpapers);
}

// setup array defining all wallpapers & define thumbnails
private void addWallpapers(Resources resources, String packageName, int list) {
    final String[] extras = resources.getStringArray(list);
    for (String extra : extras) {
        int res = resources.getIdentifier(extra, "drawable", packageName);
        if (res != 0) {
            final int thumbRes = resources.getIdentifier(extra + "_small",
                    "drawable", packageName);

            if (thumbRes != 0) {
                mThumbs.add(thumbRes);
                mImages.add(res);
            }
        }
    }
}

在“Set Wallpaper”Button上报后,AlertDialog应当与另一个版面图相提并存,该图文在Gallery上。 将包含一个<编码>TextView,附有指示、我们提议作为挂图、“Okay”代码和“Cancel”Button 的图像简介。 发布“Okay”Button时,将把图像从>ImageViewpreview上贴在系统挂图上。 InputStream。

再次感谢!

    private void selectWallpaper(int position) {
    Toast.makeText(getBaseContext(), "Select Wallpaper", Toast.LENGTH_SHORT)
            .show();

    if (mIsWallpaperSet) {
        return;
    }

    mIsWallpaperSet = true;

    Context context = this;
    // CharSequence text = "Wallpaper Set!";
    // int duration = Toast.LENGTH_LONG;
    InputStream stream = getResources().openRawResource(
            mImages.get(position));
            final Dialog accept = new Dialog(context);
    accept.setContentView(R.layout.confirm);
    accept.setTitle("Please Confirm");
    TextView instructions = (TextView) accept.findViewById(R.id.textView1);
    instructions.setText("Would you like to set this as your wallpaper?");
    ImageView wallpreview = (ImageView) accept
            .findViewById(R.id.imageView1);
    wallpreview.createFromStream(stream, "test");
    // SETUP cancel (no btn) listener
    Button cancelbtn = (Button) accept.findViewById(R.id.button2);
    cancelbtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            accept.dismiss();
        }
    });
    // SETUP Yes Btn listener
    Button okbtn = (Button) accept.findViewById(R.id.button1);
    okbtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // dismiss being used as placeholder, actually setting wallpaper
            // will be added
            accept.dismiss();
        }
    });
    accept.show();
}

{
    ;
}
最佳回答

您可以使用排外器,打破你的警惕性方言布局,并在你的主要活动中将其置于警示的视角。 你们可以利用第ById()号来为这些县安排ClickListeners听众。 这将确保你在ClickListener能够看到哺乳。

final ArrayList<Integer> mImages=new ArrayList<Integer>();
final ImageView v=findViewById(R.id.imageView);

AlertDialog d=new AlertDialog.Builder(Main.this).create();
d.setView(getLayoutInflater().inflate(R.layout.dialogView,findViewById(R.id.ROOT_LAYOUT_IN_XML_ID),false));

((ImageView)d.findViewById(R.id.YOUR_VIEW_ID)).setImageResource(mImages.get(?));

((Button)d.findViewById(R.id.cancelButton)).setOnClickListener(new OnClickListener()
{
    d.dismiss();
});
((Button)d.findViewById(R.id.acceptButton)).setOnClickListener(new OnClickListener()
{
    v.setImageResource(mImages.get(?));
    d.dismiss();
});
问题回答

暂无回答




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签