title: How to update RecyclerView when another Fragment button Click
body: <p>i have 2 tab.</p>
  
  <p>A - RecycleFragment ///////
  B - DiaryFragment</p>
  
  <p>i want update RecycleFragment when button click in DiaryFragment.</p>
  
  <pre><code>public class RecycleFragment extends Fragment {
  
      static  DBHelper dbHelper;
      public List&lt;Contact&gt; items = new ArrayList&lt;Contact&gt;();
  
      MyAdapter adapter = new MyAdapter(items);
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          dbHelper = new DBHelper(getActivity());
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.recyle_fragment, container, false);
          RecyclerView rv = (RecyclerView) rootView.findViewById(R.id.rv_recycler_view);
          LinearLayoutManager llm = new LinearLayoutManager(getActivity());
          // MyAdapter adapter = new MyAdapter(items);
  
  
          rv.setLayoutManager(llm);
          rv.setAdapter(adapter);
          adapter.addTestData();
          adapter.notifyDataSetChanged();
  
          return rv;
      }
  }
  </code></pre>
  
  <p>====================</p>
  
  <pre><code>public  class  MyAdapter extends RecyclerView.Adapter&lt;DataManager&gt; {
   static List&lt;Contact&gt; items = new ArrayList&lt;Contact&gt;();
  
  public MyAdapter(List&lt;Contact&gt; items){
      this.items = items;
  }
  
  
  @Override
  public DataManager onCreateViewHolder(ViewGroup viewGroup, int i) {
      View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.entries, viewGroup, false);
      return new DataManager(v);
  }
  
  @Override
  public void onBindViewHolder(DataManager holder, int position) {
  
      Contact item = items.get(position);
      holder.mTitle.setText(item.get1(Contact.Field.TITLE));
      holder.mDate.setText(item.get1(Contact.Field.DATE));
      holder.mMonth.setText(item.get1(Contact.Field.MONTH));
      holder.mTime.setText(item.get1(Contact.Field.TIME));
      holder.mDay.setText(item.get1(Contact.Field.DAY));
      holder.mContent.setText(item.get1(Contact.Field.CONTENT));
      holder.mMood.setImageResource(item.get2(Contact.Field.MOOD));
      holder.mWeather.setImageResource(item.get2(Contact.Field.WEATHER));
  
  }
  
  @Override
  public int getItemCount() {
      return items.size();
  }
  
  public void setItem(List&lt;Contact&gt; items){
      this.items = items;
      notifyItemChanged (0, null);
  }
  
  
  public void addTestData(){
  
      Cursor cursor = RecycleFragment.dbHelper.D_getAllData();
      if(cursor != null) {
          if (cursor.moveToFirst()) {
              do{
                  add(new Contact(cursor.getString(0),
                          cursor.getString(1),
                          cursor.getString(2),
                          cursor.getString(3),
                          cursor.getString(5),
                          cursor.getString(5),
                          cursor.getString(6),
                          cursor.getInt(7),
                          cursor.getInt(8)));
  
              }while (cursor.moveToNext());
          }
      }
  }
  
  
  public void add(Contact data){
      items.add(data);
      setItem(items);
  }
  
  }
  </code></pre>
  
  <p>========================================</p>
  
  <p>DiaryFragment in button click event</p>
  
  <pre><code>case R.id.IV_diary_save:
              if(EDT_diary_title.getText().toString().trim() != null &amp;&amp; EDT_diary_title.getText().toString().trim().length() != 0){
  
                  if( EDT_diary_content.getText().toString().trim() != null &amp;&amp; EDT_diary_content.getText().toString().trim().length() != 0){
  
                      dbHelper.D_insertData(EDT_diary_title.getText().toString(), EDT_diary_content.getText().toString(),
                              TV_diary_month.getText().toString(), TV_diary_date.getText().toString(), TV_diary_day.getText().toString(),
                              TV_diary_time.getText().toString(),
                              diaryInfoHelper.getMoodResourceId(SP_diary_weather.getSelectedItemPosition()),
                              diaryInfoHelper.getWeatherResourceId(SP_diary_mood.getSelectedItemPosition())
                      );
  
                      myAdapter.add(new Contact
                              (String.valueOf(dbHelper.getRow()),EDT_diary_title.getText().toString(), EDT_diary_content.getText().toString(),
                                      TV_diary_month.getText().toString(), TV_diary_date.getText().toString(), TV_diary_day.getText().toString(),
                                      TV_diary_time.getText().toString(),
                                      diaryInfoHelper.getMoodResourceId(SP_diary_weather.getSelectedItemPosition()),
                                      diaryInfoHelper.getWeatherResourceId(SP_diary_mood.getSelectedItemPosition())
                              ));
  
  
                      Toast.makeText(v.getContext(), "Success to Insert", Toast.LENGTH_SHORT).show();
  
  
                      ((TabActivity)getActivity()).getViewPager().setCurrentItem(0);
  
  
                      EDT_diary_title.setText("");
                      EDT_diary_content.setText("");
  
                  }else {
                      Toast.makeText(v.getContext(), "Content is Empty ", Toast.LENGTH_SHORT).show();
                      EDT_diary_content.setText("");
                  }
              }else {
                  Toast.makeText(v.getContext(), "Title is Empty ", Toast.LENGTH_SHORT).show();
                  EDT_diary_title.setText("");
              }
              break;
  </code></pre>
  
  <p>===================================================</p>
  
  <p>button click in DiaryFragment then </p>
  
  <p>moving tab RecycleFragment and</p>
  
  <p>RecycleFragment content immediately change new item insert data.</p>
  
  <p>but now when button click in DiaryFragment
  RecycleFragment not change.</p>
  
  <p>Want changing RecycleFragment. I exit RecycleFragment and restart RecycleFragment.</p>
  
  <p>please help me</p>
  
  <p>thank</p>