Payday Loan Payday Loan

Many times you needed to know the position in the listView where you long tapped, so that you know what to do in the context menu.
For finding this, there is a simple way that not involves using adapters, or listView at all. Look at code below:

  @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getMenuInflater().inflate(R.menu.edit_route_context_menu, menu);
        //below line is the key line. you write this and in info variable you have the position wished
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        int position = info.position;//do what you want with the position
    }
||||| 0 I Like It! |||||

Search

Popular

Sponsors