title: Closing dialog from inside a custom ArrayAdapter
body: <p>I have a custom dialog fragment that has a custom ArrayAdapter inside.  Each one of the list items has 3 buttons.  On the click of each button I have an <code>OnClickListener()</code> that does a function.  After the function is complete I need to have the dialog closed.  Because this is done in the ArrayAdapter I cannot call <code>dismiss()</code> like I would inside of the dialog fragment.  I tried setting up a <code>OnClickListener()</code> for the buttons inside of the dialog fragment, but I get a null pointer.</p>
  
  <p>I cannot figure out how to get a reference to the dialog fragment from inside the custom arrayAdapter.  The onclick event has to happen inside of the ArrayAdapter because it uses info specific to that list item.  Any help would be greatly appreciated.  Thank you.</p>
  
  <p>DialogFragment:</p>
  
  <pre><code>public class SavedArmyDialog extends DialogFragment {
  View mView;
  
  public static SavedArmyDialog newInstance() {
      SavedArmyDialog fragment = new SavedArmyDialog();
      return fragment;
  }
  
  public SavedArmyDialog() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      mView =  inflater.inflate(R.layout.custom_army_list, container, false);
  
      CustomArmyObjData customArmyObjData = new CustomArmyObjData();
      ArrayList&lt;CustomArmy&gt; customArmyArray = customArmyObjData.getCustomArmyArray(getActivity());
  
      CustomArmyAdapter adapter = new CustomArmyAdapter(getActivity(), customArmyArray);
  
      ListView armyList = (ListView) mView.findViewById(R.id.armyListView);
      armyList.setAdapter(adapter);
  
  
      return mView;
  }
  
  
  }
  </code></pre>
  
  <p>Custom ArrayAdapter:</p>
  
  <pre><code>    public View getView(int position, View convertView, ViewGroup parent) {
      final CustomArmy army = getItem(position);
  
      ViewHolder holder;
  
      if (convertView == null) {
          holder = new ViewHolder();
          convertView = LayoutInflater.from(getContext()).inflate(R.layout.individual_army_view, parent, false);
  
          holder.armyname = (TextView) convertView.findViewById(R.id.army_name_value);
          holder.townHall = (TextView) convertView.findViewById(R.id.townHallValue);
          holder.armyType = (TextView) convertView.findViewById(R.id.armyTypeValue);
          holder.loadButton = (Button) convertView.findViewById(R.id.loadButton);
          holder.deleteButton = (Button) convertView.findViewById(R.id.deleteButton);
          holder.gridLayout = (GridLayout) convertView.findViewById(R.id.armyGrid);
          buildArmyCountAndIconViews(army, holder.gridLayout);
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
          holder.gridLayout.removeAllViews();
          buildArmyCountAndIconViews(army, holder.gridLayout);
      }
  
      holder.armyname.setText(army.getName());
      holder.townHall.setText(army.getTownHallRequired());
      holder.armyType.setText(army.getArmyType());
      holder.loadButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              mBus.post(new LoadNewArmy(army));
              Toast.makeText(getContext(), "Woking Button", Toast.LENGTH_SHORT).show();
              //need to close the dialog from here
          }
      });
      holder.deleteButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Utilities.deleteCustomArmy(army.getName(), getContext());
              Toast.makeText(getContext(), "Army has Been Deleted", Toast.LENGTH_LONG).show();
              //need to close the dialog from here
          }
      });
  
      return convertView;
  }
  </code></pre>