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.

package com.example.menu;

import android.app.Activity;
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(R.menu.menu, menu);

                return true;

                }

         @Override
         public boolean onOptionsItemSelected(MenuItem item) {
          super.onOptionsItemSelected(item);


        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        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:

 http://developer.android.com/guide/topics/ui/menus.html 

There are many samples available.

 http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/app/MenuInflateFromXml.html 

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).

 http://www.androidguys.com/2008/09/29/whats-your-preference-part-one/ 

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

Here are two more samples:

 http://www.androidsnippets.org/snippets/40/ 
 http://www.androidsnippets.org/snippets/31/ 

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

 http://wiki.andmob.org/books 


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

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

Android Training in Germany, 18-22 January 2010:  http://bignerdranch.com 

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


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?

Thanks.
--~--~---------~--~----~------------~-------~--~----~



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
this?

Thanks.
--~--~---------~--~----~------------~-------~--~----~



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?

pskink
--~--~---------~--~----~------------~-------~--~----~



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. How to know whether bluetooth is enabled/disabled

Greetings,

How can I know whether bluetooth is enabled or disabled.

Thanks,
Arjun.

-- 

2. ContextMenu Problem - how to resolve these menu items

Hi, I am very new to Android.

I am trying to build inflate a context menu within the sample GridView
provided on the Android dev site. Eclipse tells me that the referenced
items cannot be resolved, if someone could help find where I coded
s.th. wrong, that would be great because I am stuck at the moment.
Thanks.

I posted my entire code below. I get the error message at: `if
(item.getItemId() == R.id.menu_facebook)` and the other R.id.'s

--------------------------------
This is the ShareGalleryView.java file:


     import android.app.Activity;
     import android.content.Context;
     import android.os.Bundle;
     import android.view.ContextMenu;
     import android.view.MenuInflater;
     import android.view.MenuItem;
     import android.view.View;
     import android.view.ViewGroup;
     import android.view.ContextMenu.ContextMenuInfo;
     import android.widget.BaseAdapter;
     import android.widget.GridView;
     import android.widget.ImageView;
     import android.widget.AdapterView.AdapterContextMenuInfo;

     public class ShareGalleryView extends Activity {

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.videogrid);

            GridView vGrid=(GridView) findViewById(R.id.vgrid);
            registerForContextMenu(vGrid);
            vGrid.setAdapter(new VideoAdapter(this));
        }

        public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
          super.onCreateContextMenu(menu, v, menuInfo);
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu_gallery_share, menu);
        }

        public boolean onContextItemSelected (MenuItem item){
        AdapterContextMenuInfo info = (AdapterContextMenuInfo)
item.getMenuInfo();
                if (item.getItemId() == R.id.menu_facebook)
                {
                 //TODO open fb
                        return true;

                }
                else if (item.getItemId() == R.id.menu_youtube)
                {
                        //TODO open youtube
                        return true;

                }
                else if (item.getItemId() == R.id.menu_email)
                {
                 //TODO open email
                        return true;

                }
                else if (item.getItemId() == R.id.menu_bluetooth)
                {
                        // TODO send via bluetooth
                        return true;

                }
        }

        public class VideoAdapter extends BaseAdapter {
                private Context mContext;

                public VideoAdapter(Context c) {
                    mContext = c;
            }

            public int getCount() {
                return mThumbIds.length;
            }

            public Object getItem(int position) {
                return null;
            }

            public long getItemId(int position) {
                return 0;
            }

            // create a new ImageView for each item referenced by the
Adapter
            public View getView(int position, View convertView, ViewGroup
parent) {
                ImageView imageView;
                if (convertView == null) {  // if it's not recycled,
initialize some attributes
                    imageView = new ImageView(mContext);
                    imageView.setLayoutParams(new
GridView.LayoutParams(85, 85));
 
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(8, 8, 8, 8);
                } else {
                    imageView = (ImageView) convertView;
                }

                imageView.setImageResource(mThumbIds[position]);
                return imageView;
            }

            // references to our images
            private Integer[] mThumbIds = {
                    R.drawable.sample_2, R.drawable.sample_3,
                    R.drawable.sample_4, R.drawable.sample_2,
                    R.drawable.sample_6, R.drawable.sample_3,
                    R.drawable.sample_4, R.drawable.sample_1

            };
        }
    }

and this is the menu_gallery_share.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/
android">
      <menu xmlns:android="http://schemas.android.com/apk/res/
android">
        <item android:id="@+id/menu_facebook"
              android:title="@string/Facebook" />
        <item android:id="@+id/menu_youtube"
              android:title="@string/YouTube" />
        <item android:id="@+id/menu_email"
              android:title="@string/Email" />
        <item android:id="@+id/menu_bluetooth"
              android:title="@string/Via Bluetooth" />
       </menu>
    </menu>

-- 

3. Implementing a Service - Call down to super?

4. adb device not getting recognized.

5. Do other devs get asked to list their apps on foreign market sites?

6. Instal hampir semua program ke SD card tanpa root (2.2)

7. problems installing ADT plugin "Cannot connect to keystore. This trust engine is read only."