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

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *