Android nineteenth days - I context menu

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Android nineteenth days - I context menu
 

Implementation process

       5, The list item register context menu

          . registerForContextMenu(listView)Or

            listView.setOnCreateContextMenuListener(this);

Making making making making making to register liestView context menu

          . onCreateContextMenu(ContextMenu menu, View v,

             ContextMenuInfo menuInfo): Creating a context menu list items

Making making making making making making this method each time the display context will trigger

Making making making making. Assembly context menu (menu and choose almost)

Making making making making. Set the context menu title: menu.setHeaderTitle(name);

6, Listen to the context menu

, onContextItemSelected
, On the context menu for business process
 /**
     * Each time the display context menu will trigger list items (each long press ListView to display the context menu */
    public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    // Remove the map data corresponding to the current Item
    HashMap<String, Object> map = data.get(info.position);
    // Obtain title
    String name = map.get(NAME).toString();
    // The top title set the context menu
    menu.setHeaderTitle(name);
    getMenuInflater().inflate(R.menu.menu_book_context, menu);
    }


    /**
     * Monitoring menu click */
    public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
case R.id.menu_add: // Add to
menuEidtOrAdd(null);
break;

case R.id.menu_delete: // Delete
optionsMenuDelete();
break;

case R.id.menu_good_look: // Good-looking
case R.id.menu_not_good_look: // Does not look good
optionsMenuGoodLookOrNot(itemId);
break;
}
    return super.onOptionsItemSelected(item);
    }

 

Download video code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Todd at December 07, 2013 - 2:31 PM