how to append latest data to custom base adapter list view in android?

。_饼干妹妹 提交于 2019-12-03 17:34:11
    CustomeAdapter adapter = new CustomeAdapter(GetMsgsScreen.this,newmsgResult);

define this adapter andnewmsgResult at top of your class..not a local variable inside a class..

Now, whenever you want to update the data in list view, update the values/data in newmsgResult and call adapter.notifyDataSetChanged()

I think it is happening because you are creating a new custom adapter every time you are getting new messages.. in this line

CustomeAdapter adapter = new CustomeAdapter(GetMsgsScreen.this,newmsgResult);

dont do this and try to use adapter.add(Newmessage); you can use array list to make work easier

ok.. you should have an add function in your custom adapter class for that.. you can do so by adding this to your custom adapter class

private void customadd(String newmsg)
{
  //ArrayList<String> msg=new List<String>; create this array list as a source to your adapter
  msg.add(newmsg);
adapter.notifyDataSetChanged();
}

Initially load the your list view with customAdapter using result(By assumption result is arraylist)

   CustomeAdapter adapter = new CustomeAdapter(GetMsgsScreen.this,result);
    lst.setAdapter(adapter);

once you have new value no need to create new result and adapter object, simply append you result in your adapter object,

result.add("append your new result");

then simply adapter.notifyDataSetChanged();

Dont create a new adapter. Keep the original one and pass the new data to it for appending it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!