Sam
Sam

Reputation: 4284

creating popup menu in android 2.3 GingerBread

I am an intermediate level programmer in android. Now I am developing an app which has a view. When I click that view I have to display a popup menu.

I got the following code from android developer site

public void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.actions, popup.getMenu());
    popup.show();
}

But this code is working only on API 11 and above.

Can anyone help me so that I can make a popup menu that supports also GingerBread?

Upvotes: 5

Views: 7527

Answers (4)

kalidoss rajendran
kalidoss rajendran

Reputation: 640

As my knowledge PopupMenuis not support for Android 2.3,PopupWindow only support for Android 2.3,so better to use PopupWindow in Android 2.3

Upvotes: 0

MarkoMilos
MarkoMilos

Reputation: 25

Popup menus are now available in support library v4 (PopupMenuCompat).

Upvotes: 1

Madthew
Madthew

Reputation: 686

you can use PopupWindow and showAsDropDown() instead.

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

Upvotes: 3

TronicZomB
TronicZomB

Reputation: 8747

You could try the following:

public void myDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.my_xml_layout, null);
    builder.setView(v);
    builder.set......;
    builder.show();
}

where builder.set... is where you can set the title, positive button action (ie "Ok"), negative button action (ie "Cancel"), and other options.

Upvotes: 0

Related Questions