I have a ListView whose items I fetch from a JSON response from a Web API. It basically has comments in it. The problem is that when the user adds new comment, the item gets added to the top of the List. I want the item to be added at the end.
Here is my code:-
MyList.java
private void GetComments()
{
// TODO Auto-generated method stub
scrollNews.scrollTo(0, scrollNews.getBottom());
commentsList.setVisibility(View.VISIBLE);
String items;
try
{
String getRequestForComments = myUrl;
items = new FetchItems().execute(getRequestForComments).get();
ArrayList<HashMap<String, String>> getList = new GetList().execute(items).get();
itemsAdapter = (ListAdapter) new CommentsAdapter(NewsDetails.this, getList);
commentsList.setAdapter(itemsAdapter);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ExecutionException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
mylist.xml
<ListView
android:id="@+id/android:list"
android:visibility="invisible"
android:transcriptMode="alwaysScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/getdata"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:layout_weight="6"
android:layout_gravity="bottom"
android:listSelector="@drawable/list_selector"
android:padding="5dp"/>
Can anyone help me with this?