FileDocCategorySizeDatePackage
ListContextMenu.javaAPI DocAndroid 5.1 API6587Thu Mar 12 22:22:12 GMT 2015android.view

ListContextMenu

public class ListContextMenu extends android.app.ListActivity implements View.OnCreateContextMenuListener
Exercises context menus in lists

Fields Summary
static final String
TAG
ThrashListAdapter
mAdapter
Constructors Summary
Methods Summary
public booleanonContextItemSelected(android.view.MenuItem item)

        Log.i(TAG, "Context item " + item.toString() + " selected.");
        
        return super.onContextItemSelected(item);
    
public voidonContextMenuClosed(android.view.Menu menu)

        Log.i(TAG, "Context menu closed");
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        
        mAdapter = new ThrashListAdapter(this);
        getListView().setOnCreateContextMenuListener(this);
        setListAdapter(mAdapter);
    
public voidonCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)

        
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
        
        String text = ((TextView) info.targetView).getText().toString();
        if (text.contains("[0]")) {
            menu.setHeaderTitle("This is a test of the title and the icon").setHeaderIcon(
                    android.R.drawable.sym_def_app_icon);
        } else if (text.contains("[1]")) {
            menu.setHeaderTitle("This is a test of just the title");
        } else {
            TextView textView = new TextView(this);
            textView.setText("This is a test of a custom View");
            menu.setHeaderView(textView);
        }
        
        menu.add(0, 0, 0, "Test 1");
        SubMenu sm = menu.addSubMenu(0, 0, 0, "Test 1.5 SM");
        sm.add(0, 0, 0, "CM Subitem 1");
        sm.add(0, 0, 0, "CM Subitem 2");
        sm.add(0, 0, 0, "CM Subitem 3");
        menu.add(0, 0, 0, "Test 2");
        menu.add(0, 0, 0, "Test 3");
        menu.add(0, 0, 0, "Test 4");
        menu.add(0, 0, 0, "Test 5");
        menu.add(0, 0, 0, "Test 6");
        menu.add(0, 0, 0, "Test 7");
        menu.add(0, 0, 0, "Test 8");
        menu.add(0, 0, 0, "Test 9");
        menu.add(0, 0, 0, "Test 10");
        menu.add(0, 0, 0, "Test 11");
        menu.add(0, 0, 0, "Test 12");
        menu.add(0, 0, 0, "Test 13");
        menu.add(0, 0, 0, "Test 14");
        menu.add(0, 0, 0, "Test 15");
        menu.add(0, 0, 0, "Test 16");
        menu.add(0, 0, 0, "Test 17");
        menu.add(0, 0, 0, "Test 18");
        menu.add(0, 0, 0, "Test 19");
        menu.add(0, 0, 0, "Test 20");
        menu.add(0, 0, 0, "Test 21");
        menu.add(0, 0, 0, "Test 22");
        menu.add(0, 0, 0, "Test 23");
        menu.add(0, 0, 0, "Test 24");
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        MenuItem item = menu.add(0, 0, 0, "Really long menu item name");
        item.setTitleCondensed("Long name");
        item.setIcon(R.drawable.black_square);
        
        SubMenu sm = menu.addSubMenu(0, 0, 0, "The 2nd item, a sub menu").setIcon(R.drawable.black_square_stretchable);
        item = sm.getItem();
        item.setTitleCondensed("Sub menu");
        sm.add(1, 0, 0, "Subitem 1");
        sm.add(1, 0, 0, "Subitem 2");
        sm.add(1, 0, 0, "Subitem 3");
        sm.setGroupCheckable(1, true, true);
        menu.add(0, 0, 0, "Item 3");
        menu.add(0, 0, 0, "Item 4");
        menu.add(0, 0, 0, "Item 5");
        menu.add(0, 0, 0, "Item 6");
        menu.add(0, 0, 0, "Item 7");
        menu.add(0, 0, 0, "Item 8");
        menu.add(0, 0, 0, "Item 9");
        sm = menu.addSubMenu(0, 0, 0, "Item 10 SM");
        sm.add(0, 0, 0, "Subitem 1");
        sm.add(0, 0, 0, "Subitem 2");
        sm.add(0, 0, 0, "Subitem 3");
        sm.add(0, 0, 0, "Subitem 4");
        sm.add(0, 0, 0, "Subitem 5");
        sm.add(0, 0, 0, "Subitem 6");
        sm.add(0, 0, 0, "Subitem 7");
        sm.add(0, 0, 0, "Subitem 8");
        
        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        Log.i(TAG, "Options item " + item.toString() + " selected.");
        
        return super.onOptionsItemSelected(item);
    
public voidonOptionsMenuClosed(android.view.Menu menu)

        Log.i(TAG, "Options menu closed");