Andriod實現可拖動列表

來源:互聯網
上載者:User


        在做一個應用時,有一個需求,需要實現像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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.