How to add context menu to application?

Put your problem here if it does not fit any of the other categories.

How to add context menu to application?

Postby x-files » Mon Feb 25, 2008 1:44 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.         setContentView(R.layout.main);
  6.  
  7.         findViewById(R.id.button).setOnPopulateContextMenuListener(contextMenuListener);
  8.  
  9.     }
  10.  
  11.    
  12.  
  13.     private OnPopulateContextMenuListener contextMenuListener = new OnPopulateContextMenuListener() {
  14.  
  15.          public void onPopulateContextMenu(ContextMenu menu, View view, Object obj) {
  16.  
  17.                  menu.setHeader("Title");
  18.  
  19.                  populateMenu(menu);                     
  20.  
  21.          }
  22.  
  23.     };
  24.  
  25.    
  26.  
  27.     @Override
  28.  
  29.     public boolean onCreateOptionsMenu(Menu menu) {
  30.  
  31.         super.onCreateOptionsMenu(menu);
  32.  
  33.         populateMenu(menu);
  34.  
  35.         return true;
  36.  
  37.     }
  38.  
  39.    
  40.  
  41.     private void populateMenu(Menu menu) {
  42.  
  43.         ...
  44.  
  45.     }
  46.  
  47.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.    android:orientation="vertical"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="fill_parent"
  8.  
  9.    >
  10.  
  11. <Button
  12.  
  13.         android:id="@+id/button"
  14.  
  15.    android:layout_width="fill_parent"
  16.  
  17.    android:layout_height="wrap_content"
  18.  
  19.    android:text="Hello World, MenuDemo"
  20.  
  21.    />
  22.  
  23. </LinearLayout>
  24.  
  25.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

When I click roughly 2 seconds the center button(on keyboard) context menu is shown.
But when I touching roughly 2 seconds context menu isn't shown.
What is wrong?
x-files
Developer
Developer
 
Posts: 44
Joined: Fri Jan 11, 2008 10:27 am

Top

Postby x-files » Mon Feb 25, 2008 8:05 pm

Can anybody show same example of context menu?
x-files
Developer
Developer
 
Posts: 44
Joined: Fri Jan 11, 2008 10:27 am

Postby rmeph » Tue Feb 26, 2008 9:05 am

me too........ :roll:
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 22 guests