how to remove a contact using context menu in android
<p>I try the following code to remove contact using context menu item selected by name.</p>

<pre><code>public static boolean deleteContact(Context ctx, String phone, String name) {

    Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
    Cursor cur = ctx.getContentResolver().query(contactUri, null, null, null, null);
    try {
        if (cur.moveToFirst()) {
            do {
                if (cur.getString(cur.getColumnIndex(PhoneLookup.DISPLAY_NAME)).equalsIgnoreCase(name)) {
                    String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
                    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
                    ctx.getContentResolver().delete(uri, null, null);
                    return true;
                }

            } while (cur.moveToNext());
        }

    } catch (Exception e) {
        System.out.println(e.getStackTrace());
    }
    return false;
}
</code></pre>

<p>But I dont know how to put this code to my context menu item selected</p>

<pre><code>public boolean onContextItemSelected(MenuItem item)
{
    switch (item.getItemId()) 
    {
    case 0:

        return true;
    }
    return super.onContextItemSelected(item);
    }
</code></pre>
