0

I have implemented listview and onItemClickListener which on click returns me url of image in ListView.

its' all happening in fragment, how can I create another fragment or box on top of ListView and load image in it from URL?

Here is my onItemClickListener:

chat.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        Object itm = parent.getItemAtPosition(position);
        List<String> imageLink = extractUrls(String.valueOf(itm));
        String displayLink = "no image";
        if(imageLink.size() != 0){
            displayLink = imageLink.get(0);
            //Display image in popup.
        }


    }
});
arleitiss
  • 1,304
  • 1
  • 14
  • 38
  • just create a custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog then download the image and put it in the image view: http://stackoverflow.com/questions/2471935/how-to-load-an-imageview-by-url-in-android – Tomer Shemesh Apr 28 '15 at 19:07

1 Answers1

1

This solution is quite dirty but it requires just 5 lines of code.
It uses a WebView inside an AlertDialog to download and display the image.

String displayLink = "https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png";

AlertDialog.Builder d = new AlertDialog.Builder(this);
WebView w = new WebView(this);
w.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
w.loadData("<img style=\"width:100%\" src=\""+displayLink+"\" />", "text/html", "utf-8");
d.setView(w).show();
ByteHamster
  • 4,884
  • 9
  • 38
  • 53