0

I have a ListActivity as my main activity. I want to be able to do a few things on a single item in the list i.e.

Longpress to bring up a contextmenu for that item Swipe left to right to slide a new screen from the right to edit the list item.

Does anyone have any code they can show me that does this?

JPM
  • 9,077
  • 13
  • 78
  • 137
  • Yeah I have some code that does this, write your own. – Falmarri Dec 09 '10 at 01:50
  • Okay, I should clarify that - JPM, we're not trying to be rude (okay, Falmarri is :) ), but those are very basic tasks, and the Android API demos clearly demonstrate all that. You may want to look there, and when you're stuck, ask a specific question here. – EboMike Dec 09 '10 at 01:54
  • Actually, "Swipe left to right to slide a new screen from the right to edit the list item" does not qualify as "very basic task" IMHO. Heck, I'd say it is way beyond any reasonable expectation of a "gimme the code" "question" like is posed here. – CommonsWare Dec 09 '10 at 02:00
  • Although in that instance, a search on StackOverflow could have helped. In fact, Falmarri himself posted an answer to a question about that: http://stackoverflow.com/questions/4139288/android-how-to-handle-right-to-left-swipe-gestures/4139296#4139296 - although that only deals with the gesture itself. – EboMike Dec 09 '10 at 02:14
  • I wouldn't ask it if I didn't do some searching. I have hit a brick wall. I have looked at the demos and such but nothing really hits my situation. Seems like this should be a basic thing but I as coded and recoded and tried many different ways I just can't seem to get it to work. I can either get the gesture to work or the longpress not both. And thanks Falmarri for the help ... – JPM Dec 09 '10 at 05:09

2 Answers2

4

Longpress to bring up a contextmenu for that item

See here for how to use context menus. Here is a sample project that demonstrates their use.

Swipe left to right to slide a new screen from the right to edit the list item.

See here for how to use gesture libraries. Here is a ViewSwiper that adds gestures to a ViewFlipper. Here is an implementation of a drag-and-drop ListView, based on some poorly-understood code culled from Android itself. Blending all of that together, you may be able to implement what you seek. However, this will be rather difficult, and may not result in a user interface that is very usable. I strongly encourage you to simply have list item clicks be the way to indicate to edit an item, not a gesture.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I already have context menus working in fact I have found a way to reuse context menus and have implemented longpress to bring up one and different context menu launched from OptionsMenu. Part of the problem is the List is actually a SimpleCursorAdapter and the swipe interferes with the longpress. But Thank you for your help as I am still trying to fit this all inside a ViewSwiper. – JPM Dec 09 '10 at 05:18
  • Here is another problem the MyGestureListener, when overriding onLongPress and you want to find out which row is selected the result turns out to be -1 or none. If you have a context menu coming up on long press then the menuItem is null. – JPM Dec 10 '10 at 08:49
1

I think You can use a 2 Child ViewFlipper as your Listitem. one child for a normal dispaly(a TextView maybe), another a EditText. and in case it work as you said, don't forget to set gesterListener on your ViewFlipper,do showNext or showPrevious in your OnFling method.