如何在AlertDialog框中将图像URI设置为图标?

时间:2019-07-16 03:39:36

标签: android alertdialog

我希望选择一个项目后在我的警报对话框中显示上载的图像。这行代码show_builder.setIcon(imageView);对我不起作用。

您能告诉我这段代码中我缺少什么吗?谢谢。

这是我的代码的片段:

MainActivity.java

@Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
        Student selectedStudents = studentArrayList.get(position);

        final Uri image = selectedStudents.getUriImage();
        final String lastname = selectedStudents.getStudlname();
        final String firstname = selectedStudents.getStudfname();
        final String course = selectedStudents.getStudcourse();
        final ImageView imageView = new ImageView(this);
        imageView.setImageURI(image);

        options_builder.setTitle("Choose an option");
        String [] options = {"Show", "Edit", "Delete"};

        options_builder.setItems(options, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which){
                    case 0:
                        show_builder.setTitle(""+lastname+", "+firstname+"\n"+course);
//                        show_builder.setIcon(imageView); //this line of code is not working
                        show_builder.setNeutralButton("Okay", null);

                        AlertDialog show_dialog = show_builder.show();
                        show_dialog.show();
                        break;
                    case 1:
                        Intent toedit = new Intent(MainActivity.this, EditStudentActivity.class);
//                        toedit.putExtra("student", studentArrayList.get(which));
                        startActivity(toedit);
                    case 2:
                        studentArrayList.remove(position);
                        adapter.notifyDataSetChanged();
                        Toast.makeText(getApplicationContext(), "Item removed!", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });

        AlertDialog options_dialog = options_builder.show();
        options_dialog.show();

        return true;
    }

1 个答案:

答案 0 :(得分:1)

如果需要从ImageView中的URL显示图像,建议您使用图像加载和缓存库。一些著名的是GlidePicasso