title: Accessing public array list in setPositiveButton OnClick Function
body: <p>I am currently having issues accessing <code>public array list</code> in an <code>setPositiveButton onClick</code> function. accessing it with this doesn't work. Here is my code:</p>
  
  <p><strong>Declaring the array list with title modules.</strong> </p>
  
  <pre><code>public class DisplayModulesActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
  
      ArrayList&lt;Modules&gt; modules;
      ArrayAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_display_modules);
  
          modules = new ArrayList&lt;Modules&gt;();
          modules.add(new Modules("387COM Smartphone App Development"));
  
          ListView listView = (ListView) findViewById(R.id.moduleList);
  
          adapter = new ArrayAdapter&lt;Modules&gt;(this,
                  android.R.layout.simple_list_item_1, modules);
  
          listView.setAdapter(adapter);
          registerForContextMenu(listView);
          listView.setOnItemClickListener(this);
      }
  }
  </code></pre>
  
  <p>I want to access the array list here and remove something from it <strong>(line with modules.remove(i);</strong> it does not work.</p>
  
  <pre><code>public boolean onContextItemSelected(MenuItem item) {
      if (item.getItemId() == R.id.delete_module) {
          AlertDialog.Builder confirmDel = new AlertDialog.Builder(this);
          confirmDel
                  .setMessage("Are you sure you want to delete this module and all its contents?");
          confirmDel.setCancelable(true);
          confirmDel.setPositiveButton("Yes",
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface,
                              int i) {
                          Log.v("Test", "Confirm Delete YES pressed");
                          // AdapterView.AdapterContextMenuInfo info =
                          // (AdapterView.AdapterContextMenuInfo)
                          // item.getMenuInfo();
                          // int i = info.position;
                          modules.remove(i);
                          // adapter.notifyDataSetChanged();
                      }
                  });
          confirmDel.setNegativeButton("No", null);
  
          confirmDel.show();
      }
  }
  </code></pre>
  
  <p>Any ideas please?</p>
  
  <p><strong>FIX</strong></p>
  
  <pre><code>public boolean onContextItemSelected(final MenuItem item)
  {
      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
      final int arrayItem = info.position;
  
      if(item.getItemId() == R.id.delete_module)
      {
          AlertDialog.Builder confirmDel = new AlertDialog.Builder(this);
          confirmDel.setMessage("Are you sure you want to delete this module and all its contents?");
          confirmDel.setCancelable(true);
          confirmDel.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  Log.v("Test", "Confirm Delete YES pressed");
  
                  modules.remove(arrayItem);
                  adapter.notifyDataSetChanged();
              }
          });
          confirmDel.setNegativeButton("No", null);
  
          confirmDel.show();
      }
  </code></pre>