Andriod 达成可拖动列表
发布时间:2021-11-23 13:26:17 所属栏目:教程 来源:互联网
导读:在做一个Android应用时,有一个需求,需要实现像iphone天气的城市列表界面的可拖动功能。其实android已经实现了这个控件。但是这个控件不是公共控件,而是自带音乐播放器下的一个自定义控件。具体目录在:packages/apps/Music/src/com/android/music/TouchInt
在做一个Android应用时,有一个需求,需要实现像iphone天气的城市列表界面的可拖动功能。其实android已经实现了这个控件。但是这个控件不是公共控件,而是自带音乐播放器下的一个自定义控件。具体目录在:packages/apps/Music/src/com/android/music/TouchInterceptor.java。 使用发方法很简单,因为TouchInterceptor.java是继承ListView,与Listview不同之处在于,需要注册对该Listview的监听 代码如下: public void setTrashcan(Drawable trash) { mTrashcan = trash; mRemoveMode = TRASH; } public void setDragListener(DragListener l) { mDragListener = l; } public void setDropListener(DropListener l) { mDropListener = l; } public void setRemoveListener(RemoveListener l) { mRemoveListener = l; } public interface DragListener { void drag(int from, int to); } public interface DropListener {// 拖动listview的item,如将position=1的拖动到position=5,在这里做必要数据更新 void drop(int from, int to); } public interface RemoveListener { void remove(int which); } ![]() (编辑:开发网_开封站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |