Context Menu

by MarQuel Middleton » Sun, 13 Sep 2009 06:20:09 GMT

Sponsored Links
 Im trying to set my application menus up and i cant seem to do it  can
someone help me out i would really appreciate it im real confused!! I
just want to be able to press my exit button and it close the app or
something of that nature.


import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class LimeDroid extends Activity {
    /** Called when the activity is first created.

     * @return */

        public boolean onCreateOptionsMenu(Menu menu){

                MenuInflater inflater = getMenuInflater();

                inflater.inflate(, menu);

                return true;


         public boolean onOptionsItemSelected(MenuItem item) {

    public void onCreate(Bundle savedInstanceState) {

        Intent intent = new Intent("Reverse");
        String variableToPass = null;
                intent.putExtra("INFO_TO_PASS", variableToPass);




Context Menu

by Mark Murphy » Sun, 13 Sep 2009 06:35:40 GMT


Here is a link to the menu documentation: 

There are many samples available. 

This example shows menu inflation, where you define the menu via an XML
file. There are many other samples showing onOptionsItemSelected() in
your SDK (platforms/android-1.5/samples wherever your SDK was installed). 

This example is really of how to use the preference system, but the
sample code shows onOptionsItemSelected() as well.

Here are two more samples: 

Beyond that, you can search Google for onOptionsItemSelected(). Or, you
can pick up a good book or three: 

You do not need a menu for that. The user can click the BACK button to
exit your activity.

Mark Murphy (a Commons Guy)  | 

Android Training in Germany, 18-22 January 2010: 


Sponsored Links

Context Menu

by Neilz » Wed, 14 Oct 2009 18:45:03 GMT

 Hi. I have a context menu, which appears when you press and hold over
a list item for around two seconds.

Is there a way to adjust the sensitivity of this? I'd like it to
appear more quickly, if that's possible?


Context Menu

by Neilz » Fri, 23 Oct 2009 17:27:27 GMT

 The Context Menu in my app (a ListActivity) is getting very annoying.
On new phone you have to select and hold the list item for so long
before the menu pops up, that it's really not very user friendly.

I want my context menu to pop up immediately when the list item is
selected. I can't find a way of triggering this. There is a method
onListItemClick() which tells me when an item has been clicked, but I
still can't use that info to trigger the context menu in any way.

What are my options here? Surely there must be some way of achieving


Context Menu

by skink » Fri, 23 Oct 2009 17:48:14 GMT


if you want your context menu to popup on single item selection then
how would you scroll very long list?


Context Menu

by Neilz » Fri, 23 Oct 2009 18:05:57 GMT

 Hmmm, good point :-)

The list I'm playing with isn't very long yet, so I hadn't noticed it.

The point is, I just changed phone from HTC Magic to HTC Hero, and the
hold duration to activate the menu is painfully long. It's not user
friendly - in fact I don't think a random user using this app would
even know that holding an item was an option! I want to be able to set
the duration of the hold required.


Context Menu

by Neilz » Sat, 24 Oct 2009 16:37:23 GMT

 > if you want your context menu to popup on single item selection then
how would you scroll very long list?

Having thought about it, I Don't agree with this... It's perfectly
usual for android to behave in this way. Think about when you are
scrolling through the apps how easy it is to open one of them by
mistake. You just have to get used to the touch sensitivity of the
screen and get better at scrolling, or selecting.

So, back to my original problem. If you can't adjust the sensitivity
required (I don't believe you can't!) to activate a ContextMenu, what
other options are there to pop up a menu?

Other Threads

1. Gallery tutorial issue

On trying out the 'Gallery' code given in the documentation along with the
Android 1.5, an error shows up on the 'android.R.stylable.' line, saying
that it cannot be resolved.

Is there a way to get around this problem?



2. Changing 9-patch background on a list item in runtime doesn't always redraw properly


I have a ListView containing a few different type of items, all having
their own background image and font color. In my first implementation
I implemented each type of item as its own layout with the background
image etc defined in XML (and implemented Adapter.getView() so that it
only reuses convertView if it's of the correct type).

This works fine but the performance is not that great while scrolling
since I'm inflating quite a few Views due to convertView mismatches,
so instead I tried using the same layout for all items (to benefit
fully from convertView reuse) and  changing the background image and
font size in runtime. I even keep the three background Drawables I
need as members to save time decoding them from a resource for each
item, and call View.setBackgroundDrawable() from Adapter.getView().

The problem is, sometimes the 9-patch is not correctly wrapped around
the content of the list item when using this approach. While scrolling
it usually looks correct but when the scrolling stops, or sometimes
when I just tap anywhere on the list, the background 9-patch of some
large items starts flickering and is either cropped or resized to its
original PNG size rather than stretched to wrap the content.

First of all, I suspect this is a bug? Any ideas why this happens?
Could it be that the View is not always measured to reflect the
changed content when the 9-patch is applied? I have tried adding an
extra call to View.invalidate() but it doesn't solve the problem.

Second, does this approach sound reasonable at all, or how should I go
about to optimize this scenario?



3. How to change direction of playback video

4. How does the 3D objects get touch events?

5. More Efficiency,More Benefit,Less Risk,Less Work!

6. Problem in alarmclcock

7. Writing Lat/Long to Camera EXIF