title: Fragment recyclerView adapter notifyDataSetChanged() from MainActivity
body: <p>Please find me to solve this issue , i have a list of image <code>url</code> in a <code>json</code> api ,list url api is calling from background task and after compliting called notify method its not showing </p>
  
  <p>but the <code>Recyclerview</code> doesn't refresh - only if I go back and reopen the activity - the new data is shown.</p>
  
  <p>So how can I notify the adapter that there's new data to display?</p>
  
  <p><strong>1.WallpaperFragmentAdapter.java</strong></p>
  
  <pre><code>public class WallpaperFragmentAdapter extends Fragment {
  
     List&lt;WallpaperMain&gt; wallpaperList = new ArrayList&lt;WallpaperMain&gt;();
     WallPaperAdapter wallPaperAdapter;
  
      @Bind(R.id.recyclerView)
      RecyclerView recyclerView;
  
      private int tabId ;
  
  
  
      public void settabId(int tabId){
          this.tabId=tabId;
      }
  
      public static Fragment newInstance(Context context) {
  
          WallpaperFragmentAdapter f = new WallpaperFragmentAdapter();
          return f;
      }
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          ViewGroup root = (ViewGroup) inflater.inflate(R.layout.content_main, null);
          setUpView(root);
          return root;
      }
  
      void setUpView(ViewGroup root){
          ButterKnife.bind(this, root);
          setUPList();
      }
  
      void setUPList(){
  
          new WallPaperListDownlaoderTask().execute("http://localhost:8080/api/motivation/wallpaper/wallpaper");
  
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),3);
          wallPaperAdapter = new WallPaperAdapter(wallpaperList,getActivity());
          recyclerView.setAdapter(wallPaperAdapter);
          recyclerView.setLayoutManager(gridLayoutManager);
          System.out.println(wallPaperAdapter);
          recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new RecyclerTouchListener.ClickListener() {
              @Override
              public void onClick(View view, int position) {
  
                  Intent intent;
                  intent = new Intent(getActivity(), WallpaperDeatilsActivity.class);
                  startActivity(intent);
              }
  
              @Override
              public void onLongClick(View view, int position) {
  
              }
          }));
  
  
      }
  
       class WallPaperListDownlaoderTask extends AsyncTask&lt;String,Integer,JSONArray&gt; {
  
          OkHttpClient client = new OkHttpClient();
  
           @Override
           protected void onPreExecute() {
               super.onPreExecute();
  
           }
  
          @Override
          protected JSONArray doInBackground(String... params) {
  
              String url =params[0];
  
              Request request = new Request.Builder()
                      .url(url)
                      .build();
              try{
                  Response response = client.newCall(request).execute();
                  String apiResponseString=response.body().string();
                  System.out.println("response.body().toString() ---- "+apiResponseString );
  
                  JSONArray jsonArray = new  JSONArray(apiResponseString);
  
                  List&lt;WallpaperMain&gt; wallpaperMains = new ArrayList&lt;&gt;();
  
                  for(int index =0;index&lt;jsonArray.length();index++){
  
                      try {
                          JSONObject wallpaperMainsJsonObj = jsonArray.getJSONObject(index);
                          WallpaperMain wallpaperMain = new WallpaperMain();
                          wallpaperMain.setId(wallpaperMainsJsonObj.getInt("id"));
                          Wallpaper wallpaper = new Wallpaper();
  
                          JSONObject wallpaperJsonObj = wallpaperMainsJsonObj.getJSONObject("wallpaper");
                          wallpaper.setLarge(wallpaperJsonObj.getString("large"));
                          wallpaperMain.setWallpaper(wallpaper);
                          wallpaperMains.add(wallpaperMain);
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                  }
  
                  wallpaperList =wallpaperMains;
  
                  return null;
  
              }catch (IOException e){
                  Log.v("",e.toString());
              } catch (JSONException e) {
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(JSONArray jsonArray) {
  
             super.onPostExecute(jsonArray);
              System.out.println(wallPaperAdapter);
              wallPaperAdapter.notifyDataSetChanged();
              recyclerView.setAdapter(wallPaperAdapter);
              System.out.println(wallpaperList.size());
          }
      }
  
  }
  </code></pre>
  
  <p><strong>2.WallPaperAdapter.java</strong></p>
  
  <pre><code>public class WallPaperAdapter extends RecyclerView.Adapter&lt;WallPaperAdapter.MyViewHolder&gt;{
  
  
      private List&lt;WallpaperMain&gt; wallpaperMains;
      private Context context;
  
      public WallPaperAdapter(List&lt;WallpaperMain&gt; wallpaperMains,Context context){
          this.wallpaperMains =wallpaperMains;
          this.context=context;
      }
  
      @Override
      public WallPaperAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
          View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.wallpaper_item, null);
          WallPaperAdapter.MyViewHolder viewHolder = new WallPaperAdapter.MyViewHolder(itemLayoutView);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          Glide.with(context)
                  .load("http://localhost:8080/api/motivation/wallpaper/large/37l")
                  .into(holder.waIlpapermageView);
  
         // holder.waIlpapermageView.setImageResource(R.drawable.name);
      }
  
      @Override
      public int getItemCount() {
          return wallpaperMains.size();
      }
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
  
  
          ImageView waIlpapermageView;
          public MyViewHolder(View itemView) {
              super(itemView);
              waIlpapermageView =(ImageView) itemView.findViewById(R.id.wallpaperItem_imageView);
          }
      }
  }
  </code></pre>
  
  <p><strong>OUTPUT</strong> I am getting bellow </p>
  
  <p><a href="https://i.stack.imgur.com/Ufsq7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ufsq7.png" alt="enter image description here"></a> </p>