歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Andriod 實現可拖動列表

Andriod 實現可拖動列表

日期:2017/3/1 10:17:26   编辑:Linux編程

在做一個Android應用時,有一個需求,需要實現像iphone天氣的城市列表界面的可拖動功能。其實android已經實現了這個控件。但是這個控件不是公共控件,而是自帶音樂播放器下的一個自定義控件。具體目錄在:packages/apps/Music/src/com/android/music/TouchInterceptor.java。

使用發方法很簡單,因為TouchInterceptor.java是繼承ListView,與Listview不同之處在於,需要注冊對該Listview的監聽

代碼如下:

  1. public void setTrashcan(Drawable trash) {
  2. mTrashcan = trash;
  3. mRemoveMode = TRASH;
  4. }
  5. public void setDragListener(DragListener l) {
  6. mDragListener = l;
  7. }
  8. public void setDropListener(DropListener l) {
  9. mDropListener = l;
  10. }
  11. public void setRemoveListener(RemoveListener l) {
  12. mRemoveListener = l;
  13. }
  14. public interface DragListener {
  15. void drag(int from, int to);
  16. }
  17. public interface DropListener {// 拖動listview的item,如將position=1的拖動到position=5,在這裡做必要數據更新
  18. void drop(int from, int to);
  19. }
  20. public interface RemoveListener {
  21. void remove(int which);
  22. }
Copyright © Linux教程網 All Rights Reserved