开发者

How can I allow a user to re-sort items in a list?

开发者 https://www.devze.com 2022-12-20 18:53 出处:网络
I have an Android app where users can add items to a list, and I\'d like them to be able to re-order the items in the list however they want (as opposed to just offering them different sort orders). I

I have an Android app where users can add items to a list, and I'd like them to be able to re-order the items in the list however they want (as opposed to just offering them different sort orders). It's easy enough to add a position setting for the items (they come from the DB) but what kind of UI elements are available for the user to indicate the desire开发者_运维知识库d ordering?

Is there a pattern anyone has seen implemented for this? I have not seen anything on Android that does anything like this, except the home screen which is similar but looks a little bit beyond my expertise at this point. The best I can think of is to use a long click and context menu to "move up" or "move down".


Well, there's the right answer, and my answer. :-)

The right answer is drag-and-drop. There's some code for that floating around the Android source for the Music app, but it's outside my skill level with touch events right now.

In the one case I wanted this feature, I created a list using up/down buttons to let the user resequence. Ugly, but it works.

Using a context menu, as you indicate, can certainly be made to work, but if you can spare the on-screen real estate, putting the buttons on will be easier. You might even consider toggling the button visibility on/off via an option menu, if having them on-screen the whole time will be unpleasant.

And, someday, I hope to make a drag-and-drop ReorderableListView as a reusable component...but I wouldn't hold your breath. Maybe somebody else has one that I haven't run across yet.


I just found this: Android List View Drag and Drop sort after some searching and browsing. I thought it makes sense to link it here, because this is the first question that comes up when searching for reorderable lists in android.

0

精彩评论

暂无评论...
验证码 换一张
取 消