开发者

How can I change the position of an item in ListView dynamically in android

I want to change the position of an item in ListView dynamically.How can I do that?开发者_如何学运维


The ListView is backed up by some data structure (e.g. a List<String>). So you can do

Pseudocode:

List<String> list = ...
ListView lv = ..
Adapter a = new Adapter(..., list);
lv.setOnClickListener(this);

onItemPressed(..., int position, ...) {
   tmp = list.get(0);
   list.set(0, list.get(position));
   list.set(position,tmp);
   a.notifyDataSetChanged();
}


Check the following link

This is working fine for me

http://ericharlow.blogspot.in/2010/10/experience-android-drag-and-drop-list.html

https://sites.google.com/site/ericbharlow/sample-code/DragNDrop.zip?attredirects=0&d=1


do this for change position of listview in coding

ListView.setSelection(position);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜