views:

192

answers:

1
@Override  
    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  

        super.onCreateContextMenu(menu, v, menuInfo);  
        menu.setHeaderTitle("Selection Options");  
        menu.add(0, v.getId(), 0, "Remove");  
    }  

I want my menu to say "Remove AAPL"

I would get the string AAPL from my array adapter, but I am not sure how I can access my array adapters index from this method.

A: 

Cast menuInfo to an AdapterView.AdapterContextMenuInfo object. From there, you can get the position and id of the item in the ListView that was long-tapped.

CommonsWare
AdapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo; //cant be resolved... can you show me how to cast it properly?
Sheehan Alam
@Sheehan Alam: It is not `AdapterContextMenuInfo`. It is `AdapterView.AdapterContextMenuInfo`. See this sample project: http://github.com/commonsguy/cw-android/tree/master/Database/Constants/
CommonsWare
The example only works onContextItemSelected, I am doing something similar there. How about for onCreateContextMenu? I can't cast the ContextMenuInfo...
Sheehan Alam
@Sheehan Alam: Why not? The object should be an `AdapterView.AdapterContextMenuInfo`, since there are only two concrete implementations of `ContextMenuInfo`, and you are not working with an `ExpandableListView`.
CommonsWare