这是我的第一个Android应用程序,我是编程新手,我想在AlertDialog中显示imageView,实际上我搜索了但我发现我必须在xml布局文件中指定图像!
像那样one, 我只想从java代码中获取该图像而不是来自xml,因为用户生成的图像这部分来自我的代码:
EditText et = (EditText) findViewById(R.id.editText);
final Bitmap bm = QRCode.from(et.getText().toString()).bitmap();
ImageView iv = (ImageView) findViewById(R.id.imagev);
iv.setImageBitmap(bm);
Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this);
b.setMessage("Want to save it?");
b.setView(iv);
b.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"Tapped on YES!", Toast.LENGTH_SHORT)
.show();
}
});
b.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"Tapped on DELETE!", Toast.LENGTH_SHORT)
.show();
}
});
AlertDialog ad = b.create();
ad.show();
}
});
我想要显示" iv"在对话框中,谢谢! :)
答案 0 :(得分:0)
如果要使用纯java创建ImageView。 您可以使用constructor创建ImageView。
ImageView imageView = new ImageView(getApplicationContext());
imageView.setImageResource(R.mipmap.ic_launcher);
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(imageView)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
dialog.show();
答案 1 :(得分:0)