当前位置:操作系统 > 安卓/Android >>

Andriod实现可拖动列表


        在做一个应用时,有一个需求,需要实现像iphone天气的城市列表界面的可拖动功能。其实android已经实现了这个控件。但是这个控件不是公共控件,而是自带音乐播放器下的一个自定义控件。具体目录在:packages/apps/Music/src/com/android/music/TouchInterceptor.java。

使用发方法很简单,因为TouchInterceptor.java是继承ListView,与Listview不同之处在于,需要注册对该Listview的监听
代码如下:

[java]
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); 

作者:fangchongbory
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,