我会保持这个简单。我想将一个ImageView
in设置AlertDialog
为数组中的一个图像我想设置的Drawables
图像ImageView
可以通过访问 mImages[position] 来检索。
这是一个简短的解释(下面的完整解释):简而言之 - 我需要一种方法将图像从我的主要活动传递到对话框,然后在取消dismiss
对话框并确认设置系统壁纸(从主要活动传递的图像) 然后finish();
是活动。
这是一个完整的解释:
用户会看到一个Gallery
和ImageView
上面的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);
}
}
}
}
Button
按下“设置壁纸”后,AlertDialog
应该会打开另一个预览图像,该图像的焦点位于Gallery
. 将AlertDialog
包含一个TextView
说明,我们建议设置为墙纸的图像的预览,一个“好的”Button
和一个“取消” Button
。按“确定”Button
将ImageView
通过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();
}
{
;
}