В первой функции создаю Листвью:
public void getWall(){
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
url = "https://api.vkontakte.ru/method/wall.get?owner_id=-34215577&count=10";
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
try {
responses = json.getJSONArray(TAG_RESPONSE);
for(int i = 1; i < responses.length(); i++){
JSONObject c = responses.getJSONObject(i);
String id = c.getString(TAG_ID);
Integer time = c.getInt(TAG_DATE);
String text = c.getString(TAG_TEXT);
String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(time*1000));
JSONObject likes = c.getJSONObject(TAG_LIKES);
JSONObject reposts = c.getJSONObject(TAG_REPOSTS);
//Count Likes
String likes_count = likes.getString(TAG_COUNT);
String reposts_count = reposts.getString(TAG_COUNT);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, "ПОСТ #"+id);
map.put(TAG_DATE, date);
map.put(TAG_TEXT, Html.fromHtml(text).toString());
map.put("likes_count", likes_count);
map.put("reposts_count", reposts_count);
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
***ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.item_list,
new String[] { TAG_ID,TAG_TEXT,TAG_DATE, "reposts_count", "likes_count" }, new int[] {R.id.id_item,
R.id.item_text, R.id.item_time, R.id.item_reposts,R.id.item_likes });***
lv.setAdapter(adapter);
}
Потом мне нужно добавить новый элемент:
public void getNewItemWall(int paged){
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
url = "https://api.vkontakte.ru/method/wall.get?owner_id=-34215577&count=3&offset="+paged;
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
try {
responses = json.getJSONArray(TAG_RESPONSE);
for(int i = 1; i < responses.length(); i++){
JSONObject c = responses.getJSONObject(i);
String id = c.getString(TAG_ID);
Integer time = c.getInt(TAG_DATE);
String text = c.getString(TAG_TEXT);
String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(time*1000));
JSONObject likes = c.getJSONObject(TAG_LIKES);
JSONObject reposts = c.getJSONObject(TAG_REPOSTS);
//Count Likes
String likes_count = likes.getString(TAG_COUNT);
String reposts_count = reposts.getString(TAG_COUNT);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_DATE, date);
map.put(TAG_TEXT, Html.fromHtml(text).toString());
map.put("likes_count", likes_count);
map.put("reposts_count", reposts_count);
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.item_list,
new String[] { TAG_TEXT,TAG_DATE, "reposts_count", "likes_count" }, new int[] {
R.id.item_text, R.id.item_time, R.id.item_reposts,R.id.item_likes });
lv = mContainerView.getList();
lv.setAdapter(adapter);
}
Но при парсинге нового элемента пересоздается листвью и там всего 1 элемент