title: How to delete listview dialog item from contextmenu in Android?
body: <p>I have dialog in which listview is being displayed.On long pressing items in list context menu pops-up.Now on pressing delete in Contextmenu should delete corresponding item in listview.
  Here is my code i have written so far...</p>
  
  <pre><code>public class ViewContacts extends Activity {
  
     List&lt;String&gt; contacts;
     SharedPreferences prefs;
     SharedPreferences.Editor editor;
     ArrayAdapter&lt;String&gt; adapter;
     Dialog dialog;
     ListView lv;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // TODO Auto-generated method stub
         super.onCreate(savedInstanceState);
          contacts = new ArrayList&lt;String&gt;();
         dialog = new Dialog(ViewContacts.this);
         dialog.setTitle("My Contacts");
         dialog.setContentView(R.layout.activity_mycontacts);
         dialog.setCancelable(true);
  
         dialog.show();
          contacts.add("Abc");
          contacts.add("xyx");
          contacts.add("klm");
  
         lv =(ListView)dialog.findViewById(R.id.lv);
         adapter =new ArrayAdapter&lt;String&gt;(this,R.layout.row,R.id.contacts,contacts);
         lv.setAdapter(adapter);
         registerForContextMenu(lv);
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
          ContextMenu.ContextMenuInfo menuInfo) {
  
          MenuInflater inflater =getMenuInflater();
          inflater.inflate(R.menu.menu_list, menu);
  
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      // TODO Auto-generated method stub
      AdapterContextMenuInfo info =(AdapterContextMenuInfo) item.getMenuInfo();
      switch (item.getItemId()) {
      case R.id.del_menu:
          contacts.remove(adapter.getItem(info.position));
          adapter.notifyDataSetChanged();
          return true;
      case R.id.can_menu:
         return true;
      default:
          break;
      }
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>menu_list.xml code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;
         &lt;item android:id="@+id/del_menu"
           android:title="Delete"&gt;
         &lt;/item&gt;
          &lt;item android:id="@+id/can_menu"
           android:title="Cancel"&gt;
         &lt;/item&gt;
  
  
   &lt;/menu&gt;
  </code></pre>
  
  <p>My code is not doing anything.What could be the problem?Any suggestions or alternative to this approach of deleting items from listview?</p>