ContextMenu for ListView

by Ankit Shah » Thu, 16 Jul 2009 03:48:12 GMT


Sponsored Links
 I have a ListActivity and using BaseAdapter i have populated ListItems
(Single ListItem row contains 3 views: 1 ImageView <"icon">, 1
TextView <"Title"> and 1 more TextView <"Description">).

Now When I short click on a list item, I get the position via
onListItemClick event. When I long click on the same listItem, the
context menu comes up. The thing is that there is no info on the
position (long click position/Index value).

I would like to get the selected item without requiring the user to
short click and then long click.

I have tried few things like getSelectedItem(), getSelectedItemId(),
and getSelectedItemPosition() but didn't work for me.

Help and Support would be greatly appreciated.

Thank You.
--~--~---------~--~----~------------~-------~--~----~



ContextMenu for ListView

by Mark Murphy » Thu, 16 Jul 2009 03:59:31 GMT


 


Sure there is.

Call getMenuInfo() on the MenuItem, and cast it to an
AdapterView.AdapterContextMenuInfo. You can then get the id of the item
that was clicked upon.

Here's a snippet of code from one of my book examples:

@Override
public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
                case DELETE_ID:
                        AdapterView.AdapterContextMenuInfo info=
(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();

                        delete(info.id);
                        return(true);
        }

        return(super.onOptionsItemSelected(item));
}

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Looking for Android opportunities?  http://wiki.andmob.org/hado 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


ContextMenu for ListView

by Francesco B. » Fri, 31 Jul 2009 02:58:06 GMT


 Hi, I'm interested in this topic. I have a question about the id that
returns from info.id. Is this id the same that is used by SQLite? As I
see in your example, that I suppose is taken from the developers
tutorial, you use info.id to delete an item from SQLite. But the
column in SQLite was named _id. Is this some kind of convention to
stick to? What if those items did not have an _id but a, suppose, _key
not called id? Could we do info.key?






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to control ethernet via android application

Sorry, applications can't do that.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

2. Got media player error in sdk 1.5 r2

Hi friends,

I have written a small media player app which plays media files stored
in sdcard.

For audio files I got the following exception:

E/MediaPlayerService(   35): Couldn't open fd for
content://media/KeypressReturn.ogg/audio/media
E/MediaPlayer( 3813): Unable to to create media player
E/MediaPlayerDemo( 3813): error: setDataSource failed.:
status=0x80000000
E/MediaPlayerDemo( 3813): java.io.IOException: setDataSource failed.:
status=0x80000000
E/MediaPlayerDemo( 3813):       at android.media.MediaPlayer.setDataSource
(Native Method)
E/MediaPlayerDemo( 3813):       at android.media.MediaPlayer.setDataSource
(MediaPlayer.java:610)
E/MediaPlayerDemo( 3813):       at
com.blumedialab.mediaplayer.AudioPlayerNew$6.run(AudioPlayerNew.java:
207)
E/MediaPlayerDemo( 3813):       at java.lang.Thread.run(Thread.java:1058)


For video files, I got the following exception:

E/MediaPlayerService(   35): Couldn't open fd for
content://media/664771_dl_qcif.mp4/video/media
E/MediaPlayer( 3813): Unable to to create media player
W/VideoView( 3813): Unable to open content: 
content://media/664771_dl_qcif.mp4/video/media
W/VideoView( 3813): java.io.IOException: setDataSource failed.:
status=0x80000000
W/VideoView( 3813):     at android.media.MediaPlayer.setDataSource(Native
Method)
W/VideoView( 3813):     at android.media.MediaPlayer.setDataSource
(MediaPlayer.java:610)
W/VideoView( 3813):     at android.widget.VideoView.openVideo
(VideoView.java:195)
W/VideoView( 3813):     at android.widget.VideoView.access$1700
(VideoView.java:48)
W/VideoView( 3813):     at android.widget.VideoView$6.surfaceCreated
(VideoView.java:418)
W/VideoView( 3813):     at android.view.SurfaceView.updateWindow
(SurfaceView.java:352)
W/VideoView( 3813):     at android.view.SurfaceView.dispatchDraw
(SurfaceView.java:259)
W/VideoView( 3813):     at android.view.View.draw(View.java:5841)
W/VideoView( 3813):     at android.view.SurfaceView.draw(SurfaceView.java:
247)
W/VideoView( 3813):     at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
W/VideoView( 3813):     at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
W/VideoView( 3813):     at android.view.View.draw(View.java:5841)
W/VideoView( 3813):     at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
W/VideoView( 3813):     at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
W/VideoView( 3813):     at android.view.View.draw(View.java:5841)
W/VideoView( 3813):     at android.widget.FrameLayout.draw
(FrameLayout.java:352)
W/VideoView( 3813):     at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
W/VideoView( 3813):     at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
W/VideoView( 3813):     at android.view.View.draw(View.java:5841)
W/VideoView( 3813):     at android.widget.FrameLayout.draw
(FrameLayout.java:352)
W/VideoView( 3813):     at com.android.internal.policy.impl.PhoneWindow
$DecorView.draw(PhoneWindow.java:1847)
W/VideoView( 3813):     at android.view.ViewRoot.draw(ViewRoot.java:1217)
W/VideoView( 3813):     at android.view.ViewRoot.performTraversals
(ViewRoot.java:1030)
W/VideoView( 3813):     at android.view.ViewRoot.handleMessage
(ViewRoot.java:1482)
W/VideoView( 3813):     at android.os.Handler.dispatchMessage
(Handler.java:99)
W/VideoView( 3813):     at android.os.Looper.loop(Looper.java:123)
W/VideoView( 3813):     at android.app.ActivityThread.main
(ActivityThread.java:3948)
W/VideoView( 3813):     at java.lang.reflect.Method.invokeNative(Native
Method)
W/VideoView( 3813):     at java.lang.reflect.Method.invoke(Method.java:
521)
W/VideoView( 3813):     at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
W/VideoView( 3813):     at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:540)
W/VideoView( 3813):     at dalvik.system.NativeStart.main(Native Method)

Can any one please help me solve this problem.

Thanks,
Manoj.

--~--~---------~--~----~------------~-------~--~----~

3. Flash Player 10 Coming to Android in October

4. How to control ethernet via android application

5. Problem when set system clock using SystemClock.setCurrentTimeMillis

6. OpenGL Textures must specify GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER

7. Need Soft Keyboard & IME Details