I'm making a blog reader for Android and problem is I'm a new in programming. Trying to get data from Json. I did it for String data("title","author"), but I don't know how to do it for images ("thumbnail"). My question is: how to add "thumbnail" at the left part of the listView in front of "title" and "author".
{
"id": 109,
"url": "http://integrallab.ru/index.php/categorii-so-statyami/2013-10-25-13-26-29/3-ideas",
"title": "Article title",
"date": "2015-03-17 09:21:43",
"author": "Nikolai Boiko",
"thumbnail": "http://integrallab.esy.es/pic/3_things.jpg"
},
the code is:
......
private final String KEY_TITLE = "title";
private final String KEY_AUTHOR = "author";
.....
private void handleBlogResponse() {
mProgressBar.setVisibility(View.INVISIBLE);
if (mBlogData == null) {
updateDisplayForError();
} else {
try {
JSONArray jsonPosts = mBlogData.getJSONArray("posts");
ArrayList<HashMap<String, String>> blogPosts =
new ArrayList<HashMap<String, String>>();
for (int i=0; i<jsonPosts.length(); i++){
JSONObject post = jsonPosts.getJSONObject(i);
String title = post.getString(KEY_TITLE);
title = Html.fromHtml(title).toString();
String author = post.getString(KEY_AUTHOR);
author = Html.fromHtml(author).toString();
HashMap<String, String> blogPost = new HashMap<String, String>();
blogPost.put(KEY_TITLE, title);
blogPost.put(KEY_AUTHOR, author);
blogPosts.add(blogPost);
}
String[] keys = { KEY_TITLE, KEY_AUTHOR };
int[] ids = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, blogPosts,
android.R.layout.simple_list_item_2, keys,ids);
setListAdapter(adapter);
} catch (JSONException e) {
logException(e);
}
}
Thanks for your attention!
0 comments:
Post a Comment