title: ListView within DialogFragment will not keep up to date
body: <p>I'm having a really annoying problem with DialogFragments and backstacks.</p>
  
  <p>I have a MainActivity that hosts an ActiveMenuFragment.</p>
  
  <p>ActiveMenuFragment has a button that launches a DialogFragmentActionSelector (All methods are run from MainActivity forced interface methods):</p>
  
  <pre><code>  /**
      * Opens the action selection dialog, so the user may pick an action to
      * begin.
      */
     @Override
     public void openActionSelector() {
        actionSelectorFragment = DialogFragmentActionSelector.newInstance();
        Bundle args = new Bundle();
        args.putSerializable("Profile", currentProfile);
        actionSelectorFragment.setArguments(args);
        FragmentTransaction ft = this.getFragmentManager().beginTransaction();
        ft.addToBackStack("Action Selector");
        actionSelectorFragment.show(ft, "Action Selector");
     }
  </code></pre>
  
  <p>This fragment displays a ListView with the list of actions. Everything is fine at this point. Even previously added new actions will show up here. Now, if the user wants to define a new action, they press a button in the DialogFragment that launches DialogFragmentDefineNewAction:</p>
  
  <pre><code>/**
      * Opens the action selection dialog, so the user may pick an action to
      * begin.
      */
     @Override
     public void openActionSelector() {
        actionSelectorFragment = DialogFragmentActionSelector.newInstance();
        Bundle args = new Bundle();
        args.putSerializable("Profile", currentProfile);
        actionSelectorFragment.setArguments(args);
        FragmentTransaction ft = this.getFragmentManager().beginTransaction();
        ft.addToBackStack("Action Selector");
        actionSelectorFragment.show(ft, "Action Selector");
     }
  </code></pre>
  
  <p>After user has entered in their new action's data, they hit the confirm button, which is SUPPOSED to update the ListView within the previous fragment (DialogFragmenActionSelector), but does not. It shows the same old 8 actions every time I return to it via the backstack.</p>
  
  <pre><code>   /**
      * Takes the action defined in the DefineNewAction fragment and adds it to
      * the user dictionary.
      */
     @Override
     public void addNewActionToDictionary(Action toAdd) {
        currentProfile.getDictionary().addDefinition(toAdd);
        actionSelectorFragment.updateProfile(currentProfile);
     }
  </code></pre>
  
  <p>For reference, here is the entire DialogFragmentActionSelector, with its ArrayAdapter included:</p>
  
  <pre><code>public class DialogFragmentActionSelector extends DialogFragment implements
        OnClickListener {
  
     private EditText searchBar;
     private Button defineNewActionBtn;
     private ListView actionList;
     private UserProfile user;
     private ListViewInterface mInterface;
     private ActionsAdapter adapter;
  
     public interface ListViewInterface {
  
        void openDefineNewAction();
  
  
  
        void setActiveMenuActionBar(String action);
     }
  
  
  
     public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof ListViewInterface) {
           mInterface = (ListViewInterface) activity;
        } else {
           throw new ClassCastException(activity.toString()
                 + " must implement ListViewInterface");
        }
     }
  
  
  
     /**
      * Constructor for the fragment.
      * 
      * @return
      */
     public static DialogFragmentActionSelector newInstance() {
        DialogFragmentActionSelector dfm = new DialogFragmentActionSelector();
        return dfm;
     }
  
  
  
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {
        View toReturn = inflater.inflate(
              R.layout.fragment_action_selector_layout, container, false);
        user = (UserProfile) this.getArguments().get("Profile");
        searchBar = (EditText) toReturn.findViewById(R.id.action_search_bar);
        searchBar.addTextChangedListener(new TextWatcher() {
  
           @Override
           public void afterTextChanged(Editable arg0) {
           }
  
  
  
           @Override
           public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                 int arg3) {
           }
  
  
  
           @Override
           public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                 int arg3) {
              adapter.updateList();
              adapter.getFilter().filter(arg0);
           }
        });
        defineNewActionBtn = (Button) toReturn
              .findViewById(R.id.define_new_action);
        defineNewActionBtn.setOnClickListener(this);
        actionList = (ListView) toReturn.findViewById(R.id.actions_list);
        ArrayList&lt;Action&gt; allActions = user.getDictionary().getAllActions();
        adapter = new ActionsAdapter(this.getActivity(),
              android.R.layout.simple_list_item_1, allActions, inflater);
        actionList.setAdapter(adapter);
        actionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
           @Override
           public void onItemClick(AdapterView&lt;?&gt; parent, View clickedView,
                 int index, long id) {
              Action selectedAction = (Action) parent.getItemAtPosition(index);
              mInterface.setActiveMenuActionBar(selectedAction.getActionName());
              dismiss();
           }
        });
        return toReturn;
     }
  
  
  
     public void updateProfile(UserProfile updatedProfile) {
        user = updatedProfile;
        ArrayList&lt;Action&gt; allActions = user.getDictionary().getAllActions();
        adapter = new ActionsAdapter(this.getActivity(),
              android.R.layout.simple_list_item_1, allActions, getActivity()
                    .getLayoutInflater());
        actionList.setAdapter(adapter);
        actionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
           @Override
           public void onItemClick(AdapterView&lt;?&gt; parent, View clickedView,
                 int index, long id) {
              Action selectedAction = (Action) parent.getItemAtPosition(index);
              mInterface.setActiveMenuActionBar(selectedAction.getActionName());
              dismiss();
           }
        });
        // this.updateListView();
     }
  
  
  
     private void updateListView() {
        adapter.updateList();
     }
  
     // TODO FIX CONSTRUCTOR. UPON RETURNING, IT REVERTS TO DEFAULT 8 ACTIONS
     // RATHER THAN NEW ONES.
     private class ActionsAdapter extends ArrayAdapter&lt;Action&gt; implements
           Filterable {
  
        LayoutInflater inflater;
        ArrayList&lt;Action&gt; actionsList;
  
  
  
        public ActionsAdapter(Context context, int resId,
              ArrayList&lt;Action&gt; objects, LayoutInflater inflater) {
           super(context, resId, objects);
           this.actionsList = objects;
           this.inflater = inflater;
        }
  
  
  
        @Override
        public int getCount() {
           return actionsList.size();
        }
  
  
  
        @Override
        public Action getItem(int position) {
           return actionsList.get(position);
        }
  
  
  
        @Override
        public long getItemId(int position) {
           return this.getItem(position).hashCode();
        }
  
  
  
        public void updateList() {
           ArrayList&lt;Action&gt; allActions = user.getDictionary().getAllActions();
           actionsList = allActions;
           notifyDataSetInvalidated();
           // notifyDataSetChanged();
        }
  
  
  
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
           ViewHolder holder = null;
           Action toWrap = actionsList.get(position);
           if (convertView == null) {
              holder = new ViewHolder();
              convertView = inflater.inflate(
                    R.layout.listview_row_action_selector, parent, false);
              holder.actionName = (TextView) convertView
                    .findViewById(R.id.action_title);
              convertView.setTag(holder);
           } else
              holder = (ViewHolder) convertView.getTag();
           holder.actionName.setText(toWrap.getActionName());
           return convertView;
        }
  
        private class ViewHolder {
  
           TextView actionName;
        }
  
  
  
        /**
         * Filters the adapter's database.
         */
        @Override
        public Filter getFilter() {
           Filter filter = new Filter() {
  
              @Override
              protected FilterResults performFiltering(CharSequence constraint) {
                 FilterResults results = new FilterResults();
                 ArrayList&lt;Action&gt; matchingActions = new ArrayList&lt;Action&gt;();
                 for (int i = 0; i &lt; actionsList.size(); i++) {
                    Action actionToCheck = actionsList.get(i);
                    ArrayList&lt;String&gt; actionTags = actionToCheck.getTags();
                    String searchQuery = constraint.toString();
                    boolean foundMatch = false;
                    int k = 0;
                    int tagSize = actionTags.size();
                    if (tagSize != 0) {
                       while (!foundMatch &amp;&amp; k &lt; tagSize) {
                          if (actionTags.get(k).contains(searchQuery)) {
                             matchingActions.add(actionToCheck);
                             foundMatch = true;
                          }
                          k++;
                       }
                    }
                 }
                 results.count = matchingActions.size();
                 results.values = matchingActions;
                 return results;
              }
  
  
  
              @SuppressWarnings("unchecked")
              @Override
              protected void publishResults(CharSequence constraint,
                    FilterResults results) {
                 // actionsList.clear();
                 actionsList = (ArrayList&lt;Action&gt;) results.values;
                 adapter.notifyDataSetChanged();
              }
           };
           return filter;
        }
     }
  
  
  
     @Override
     public void onClick(View v) {
        switch (v.getId()) {
        case R.id.define_new_action:
           mInterface.openDefineNewAction();
           break;
        default:
           break;
        }
     }
  
  
  
     public void addNewActionToDictionary(Action toAdd) {
        user.getDictionary().addDefinition(toAdd);
        adapter.add(toAdd);
        adapter.updateList();
     }
  }
  </code></pre>
  
  <p>Am I supposed to use notifyDataSetChanged() or invalidated? Because it isn't working on my adapter.</p>
  
  <p>If I close all the dialogs and open them up again, the updated actions are shown in the listview. Why?</p>
  
  <p>Also, I feel as though I am doing things inefficiently and making things more complicated than they need to be. A UserProfile object also holds the Actions Dictionary and other information that pertains to the user. Should the host activity hold on to this and modify it, or should the ActiveMenu fragment handle it?</p>