我想动态更改ListView中项目的位置。我该怎么做?
答案 0 :(得分:4)
ListView由一些数据结构(例如List<String>
)备份。所以你可以做到
伪代码:
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();
}
答案 1 :(得分:3)
检查以下链接
这对我来说很好
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
答案 2 :(得分:0)
在编码中改变listview的位置
ListView.setSelection(position);