title: communicating between gridviews inside a single fragment in android
body: <p>I have a ViewPager using the Android support framework, which loads three fragments. The user can navigate between them by swiping.</p>
  
  <p>The second fragment contains two GridViews, each filled with Buttons, using an Adapter.</p>
  
  <p>The two GridViews are named (in XML) left_buttons and right_buttons. left_buttons is controlled by CategoryAdapter that extends BaseAdapter, and right_buttons is controlled by ItemAdapter that also extends BaseAdapter.</p>
  
  <p>The problem that I'm having is that when a user clicks a button in CategoryAdapter, I would like to call notifyDataSetChanged() on ItemAdapter, followed by invalidateViews() on the associated GridView. Because the two adapters are created within the same fragment MenuFragment, I'm struggling to find the best way to communicate between them.</p>
  
  <p>I've seen a lot of answers on communicating between fragments, and between fragments  and activities, and so on. I tried getting a reference to R.id.right_buttons from within the CategoryAdapter, but couldn't find a solution (since no access to findViewById etc).</p>
  
  <p>Then, I read some answers that suggested I need to create a method in the Fragment, so I tried the following in MenuFragment.class:</p>
  
  <pre><code>public void updateRightGrid() {
  
  //grab a reference to the right hand grid right_buttons
  GridView rightButtons = (GridView) getView().findViewById(R.id.right_buttons);
  
      //get the adapter that is controlling right_buttons
  ItemAdapter menuItemAdapter = (ItemAdapter) rightButtons.getAdapter();
  
      //tell this adapter that we have some new data, so please refresh
  menuItemAdapter.notifyDataSetChanged();
  
  //force the grid to refresh
  rightButtons.invalidateViews();
  
  }
  </code></pre>
  
  <p>The problem is that I still can't find a way to call this method from the CategoryAdapter. Ive created an inner class that implements OnClickListener, and in public void onClick(View v) I'm trying to call that fragment's method updateRightGrid(). I have access to the context through the variable mContext, but that doesn't seem to help.</p>
  
  <p>Any help would be much appreciated!</p>