如何在android

时间:2017-01-21 06:59:26

标签: android json android-alertdialog

我编写如下代码来创建alertdialog。警报框工作正常但如何将图像添加到alertbox?标题和消息是从我的数据库解析的字符串。我需要动态地从数据库添加图像。

  private AlertDialog.Builder builder;
   public void onClick(View v) {
               builder = new AlertDialog.Builder(ProfileViewActivity.this).setTitle(ser_name)
                                        .setMessage(desc);
               builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int which) {
                      dialog.cancel();
               }
               }).show();

1 个答案:

答案 0 :(得分:0)

将布局扩展到警报框

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

LayoutInflater inflater = this.getLayoutInflater();

View dialogView = inflater.inflate(R.layout.alert_label_editor, null);

dialogBuilder.setView(dialogView);
ImageView imgview = (ImageView) dialogView.findViewById(R.id.img);
imgview.setResource(R.drawable.img);
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
  

让你自己的布局