How to make a ListView with draggable items?

后端 未结 1 1459
一生所求
一生所求 2021-02-06 14:28

I was looking for a ListPreference in which the user can change the order of items from a list. The items would be draggable and can be re-ordered by the user.

I saw thi

相关标签:
1条回答
  • 2021-02-06 14:57

    There is no built-in widget to do this, but you may want take a look at the custom implementation used by the AOSP music player to allow for re-ordering of songs in playlists.

    TouchInterceptor.java

    That's the class which is extending ListView and is responsible for handling all of the MotionEvents and re-ordering its items, as well as detecting swipes for deleting items. You can see it implemented into an activity here in the TrackBrowserActivity.java class.

    It has three interfaces you should also be aware of: DragListener, DropListener, and RemoveListener. You can use these interfaces to provide it callbacks to fire for those events, so that you can update changes made to the list order to your SavedPreferences (since the ListView will not handle that for you).

    You can easily extend or modify the TouchInterceptor class to add additional functionality since the low-level stuff is all there for you.

    0 讨论(0)
提交回复
热议问题