0

I'm trying to create a simple app that loading photos from a website (like 9gag). I'm using jSoup and asyncTask. The problem is when i'm running the app it shows me only the url's of the images.. what can I do in order to display the image in the listView and not the url's. here's my LoadImages class:

public class LoadImages extends AsyncTask<String, Integer, Elements> {

    private ArrayAdapter adapter;
    private ArrayList list;

    public LoadImages(ArrayList list, ArrayAdapter adapter)
    {
        this.list = list;
        this.adapter = adapter;
    }

    @Override
    protected Elements doInBackground(String... params) {
         org.jsoup.nodes.Document doc = null;
            try
            {
                doc =Jsoup.connect("http://mongol.co.il/").get();
                return  doc.select("img[src$=.png]");
            }
            catch (IOException e1)
            {
                e1.printStackTrace();
            }
        return null;
    }

    @Override
    protected void onPostExecute(Elements result) {
        super.onPostExecute(result);
        for ( org.jsoup.nodes.Element div : result )
        {
            list.add(div);
        }
        adapter.notifyDataSetChanged();

    }

}

And here's my mainActivity:

public class MainActivity extends Activity{

    private ListView listView;
    private ArrayAdapter adapter;
    private ArrayList list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
         listView = (ListView) findViewById( R.id.listview); 
         list = new ArrayList();

          adapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_1, list);

            listView.setAdapter(adapter);
            new LoadImages(list, adapter).execute();


    }

}

Jalayn
  • 8,934
  • 5
  • 34
  • 51
Avi2107
  • 15
  • 6

1 Answers1

0

Show images, not URL strings. Look at this answer for more info:

Android: Image Reading from URL

Is there another way to display image from url?

Community
  • 1
  • 1
MariuszS
  • 30,646
  • 12
  • 114
  • 155