0

I want the uploaded image to be shown in my alert dialog box when an item is selected. This line of code show_builder.setIcon(imageView); is not working for me.

Can you please tell me what am I missing in this code? Thanks.

Here is a snippet of my code:

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;
    }
no_profile
  • 387
  • 5
  • 15
  • Where is `show_builder` initialized? If `show_builder` is the object of AlertDialog.Builder` the show_builder.setIcon(imageView);` is used to show small icon alongside the start of dialog title. You should use a custom view to show large images. – Sagar Chapagain Jul 16 '19 at 06:19

1 Answers1

1

If you need to display an image from a url in an ImageView, I recommend you to use an image loading and caching libraries. Some well-known ones are Glide and Picasso.

rminaj
  • 560
  • 6
  • 28