简体   繁体   English

在listview android上添加项目

[英]add items on top of the listview android

I have a listview and I am using list.add(mylist) and adapter.notifydatasetchanged() ,its adding the items below the existing list ,How Do I add the Items on Top of the List. 我有一个listview,我使用list.add(mylist)和adapter.notifydatasetchanged(),它添加了现有列表下面的项目,如何在列表顶部添加项目。

Eg: If I receive new msgs It should be on top of the existing list. 例如:如果我收到新的消息,它应该在现有列表的顶部。

Thanks in Advance. 提前致谢。

Use add(int index, E object) . 使用add(int index, E object) Where index = 0 . 其中index = 0

Actually, if you bind your adapter to your ListView, you can also just insert the item into your adapter with the position (in this case 0) 实际上,如果将适配器绑定到ListView,也可以将项目插入适配器中的位置(在本例中为0)

list.setAdapter(adapter);

... ...

adapter.insert(data, 0);

It shoudl update by itself because you had it bound 它会自行更新,因为你已经绑定了它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM