Search in sources :

Example 31 with AdapterContextMenuInfo

use of android.widget.AdapterView.AdapterContextMenuInfo in project AndroidTraining by mixi-inc.

the class MainActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() != R.id.DeleteListItem && item.getItemId() != R.id.AddListItem) {
        return false;
    }
    // MenuItemからContextMenuInfoを取得し、AdapterContextMenuInfoにキャストします
    ContextMenuInfo menuInfo = item.getMenuInfo();
    AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo;
    // AdapterContextMenuInfoから長押ししたリストアイテムのpositionを取得します
    int position = adapterInfo.position;
    // ListViewから長押しされたリストアイテムを取得します
    Book book = (Book) mListView.getItemAtPosition(position);
    if (item.getItemId() == R.id.DeleteListItem) {
    // TODO:Adapterを使用して長押ししたデータを削除してください
    } else if (item.getItemId() == R.id.AddListItem) {
    // TODO:Adapterを使用して長押ししたデータを追加してください
    }
    return true;
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo)

Example 32 with AdapterContextMenuInfo

use of android.widget.AdapterView.AdapterContextMenuInfo in project android_frameworks_base by DirtyUnicorns.

the class SelectPrinterActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (view == mListView) {
        final int position = ((AdapterContextMenuInfo) menuInfo).position;
        PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
        menu.setHeaderTitle(printer.getName());
        // Add the select menu item if applicable.
        if (printer.getStatus() != PrinterInfo.STATUS_UNAVAILABLE) {
            MenuItem selectItem = menu.add(Menu.NONE, R.string.print_select_printer, Menu.NONE, R.string.print_select_printer);
            Intent intent = new Intent();
            intent.putExtra(EXTRA_PRINTER, printer);
            selectItem.setIntent(intent);
        }
        // Add the forget menu item if applicable.
        if (mPrinterRegistry.isFavoritePrinter(printer.getId())) {
            MenuItem forgetItem = menu.add(Menu.NONE, R.string.print_forget_printer, Menu.NONE, R.string.print_forget_printer);
            Intent intent = new Intent();
            intent.putExtra(EXTRA_PRINTER_ID, printer.getId());
            forgetItem.setIntent(intent);
        }
    }
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PrinterInfo(android.print.PrinterInfo)

Aggregations

AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)32 Intent (android.content.Intent)9 MenuItem (android.view.MenuItem)6 Cursor (android.database.Cursor)5 PrinterInfo (android.print.PrinterInfo)5 MenuInflater (android.view.MenuInflater)4 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)2 Account (com.fsck.k9.Account)2 MalformedURLException (java.net.MalformedURLException)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 ContextMenu (android.view.ContextMenu)1 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1 carnero.cgeo.filter.cgFilterBySize (carnero.cgeo.filter.cgFilterBySize)1 carnero.cgeo.filter.cgFilterByType (carnero.cgeo.filter.cgFilterByType)1 BaseAccount (com.fsck.k9.BaseAccount)1 Identity (com.fsck.k9.Identity)1 SearchAccount (com.fsck.k9.search.SearchAccount)1 BaseEntity (com.xabber.android.data.entity.BaseEntity)1