开发者

Android Image URL to table row

I would like to dynamically add some images from this page to the rows from my table.

This is my code so far:

 TableLayout tableView = (TableLayout) findViewById(R.id.tableView);
    TableRow row = new TableRow(this);
    ImageView im;
    im = new ImageView(this);
    im.setImageResource(R.drawable.rss);
    row.addView(im, new TableRow.LayoutParams(50, 50)); 
    tableView.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.W开发者_运维知识库RAP_CONTENT));

Now... how can I make, for example, the image with the man with sunglasses, to be part of my table row?

PS: I would like my application to fetch each day the images, without me changing the code. That website updates one day to another, changing the news and the images.


Do you have an API from golfnews?

My norwegian is a bit rusty to be honest. So I can't really search around on the page.

Do you have any code for fetching the news? Or just one row in a tableview with an rss button? More or less.

You have as I see it three options, either use their api if they have one. You probably need to talk to them.

  1. Use the API, should give you image in base64 or similar if they have one.

  2. Use the RSS feed to fetch an index of the news and then parse each page and download the image in a temporary folder.

  3. Parse the homepage of golfnews.no and download the different pictures/cache them on the device.

For parsing homepages check the answers to this question: Parse HTML in Android


For downloading images from URL

private Drawable loadImageFromWebOperations(String url)
{
  try
    {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    } catch (Exception e)
    {
        Log.v("EXCEPTION ", ""+e.getMessage());
        return null;
    }

}

And for adding images dynamically to table you can check this Link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜