title: Android java.lang.IllegalStateException: The content of the adapter has changed but ExtendableListView did not receive a notification
body: <p>I am using two listview in single activity. When i click on first button, listview1 is filled. And when i click on second button, listview2 is filled. But in between some error was occurred. I didn't get what was the problem.</p>
  
  <p>Stacktrace is,</p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.icanstudioz.izabuy, PID: 18665
  java.lang.IllegalStateException: The content of the adapter has changed but ExtendableListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ExtendableListView(2131689644, class com.etsy.android.grid.StaggeredGridView) with Adapter(class com.icanstudioz.izabuy.adapter.FavoritesAdapter)]
          at com.etsy.android.grid.ExtendableListView.layoutChildren(ExtendableListView.java:559)
          at com.etsy.android.grid.StaggeredGridView.layoutChildren(StaggeredGridView.java:358)
          at com.etsy.android.grid.ExtendableListView.onLayout(ExtendableListView.java:513)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:562)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
          at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
          at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:907)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
          at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
          at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
          at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
          at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
          at android.view.View.layout(View.java:15125)
          at android.view.ViewGroup.layout(ViewGroup.java:4862)
          at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2323)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2029)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1192)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6231)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
          at android.view.Choreographer.doCallbacks(Choreographer.java:591)
          at android.view.Choreographer.doFrame(Choreographer.java:560)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
          at android.os.Handler.handleCallback(Handler.java:808)
          at android.os.Handler.dispatchMessage(Handler.java:103)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:5292)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>code is, for first lisview,</p>
  
  <pre><code>public void getFavorite() throws JSONException {
      IzabuyServer.get("h2app/api/product/data_list/", params,
              new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers,
                                        JSONArray response) {
                      super.onSuccess(statusCode, headers, response);
                      try {
                          everyList.clear();
                          GsonBuilder gsonBuilder = new GsonBuilder();
                          gsonBuilder.registerTypeAdapter(Favorites.class,
                                  new Favorites());
  
                          Gson gson = gsonBuilder.create();
                          everyList = gson.fromJson(response.toString(),
                                  new TypeToken&lt;List&lt;Favorites&gt;&gt;() {
                                  }.getType());
  
                          if (response.length() &lt;= 0) {
                              tv = (TextView) findViewById(R.id.no_text);
                              tv.setVisibility(View.VISIBLE);
                              list.setVisibility(View.GONE);
                              mSwipeRefreshLayout.setEnabled(false);
                              mSwipeRefreshLayout2.setEnabled(false);
                              if (db.getString("type").equalsIgnoreCase("2")) {
                                  tv.setText(getResources().getString(R.string.fav_empty));
                              } else if (db.getString("type").equalsIgnoreCase("3")) {
                                  tv.setText(getResources().getString(R.string.rec_empty));
                              }
                          } else {
                              tv = (TextView) findViewById(R.id.no_text);
                              list2.setVisibility(View.GONE);
                              list.setVisibility(View.VISIBLE);
                              tv.setVisibility(View.GONE);
                              mSwipeRefreshLayout.setEnabled(true);
                              mSwipeRefreshLayout2.setEnabled(false);
                              adapterFavorite = new FavoritesAdapter(MainScreenActivity.this,
                                      everyList);
                              list.setAdapter(adapterFavorite);
                              list.requestLayout();
                              list.setSelection(0);
                              list.setColumnCount(3);
                              adapterFavorite.notifyDataSetChanged();
  
                          }
  
                          if (pDialog != null) {
                              pDialog.dismiss();
                          }
  
  
                          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                              @Override
                              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                                      int position, long id) {
                                  Intent i = new Intent(MainScreenActivity.this, ItemDetailActivity.class);
                                  i.putExtra("product_id", everyList.get(position).getId());
                                  startActivity(i);
                              }
                          });
                          mSwipeRefreshLayout.setRefreshing(false);
  
                      } catch (NullPointerException e) {
                          e.printStackTrace();
                          mSwipeRefreshLayout.setRefreshing(false);
                      } catch (IllegalStateException e) {
                          e.printStackTrace();
                          mSwipeRefreshLayout.setRefreshing(false);
                      }
  
                      if (pDialog != null) {
                          pDialog.dismiss();
                      }
  
                  }
              });
  }
  </code></pre>
  
  <p>code is, for second lisview,</p>
  
  <pre><code>public void getSponsor() throws JSONException {
      IzabuyServer.get("h2app/api/product/data_list/", params,
              new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers,
                                        JSONArray response) {
                      super.onSuccess(statusCode, headers, response);
  
                      Log.e("sponsor", response.toString());
  
                      try {
                          sponserList.clear();
                          everyList.clear();
                          GsonBuilder gsonBuilder = new GsonBuilder();
                          gsonBuilder.registerTypeAdapter(Sponsors.class,
                                  new Sponsors());
  
                          Gson gson = gsonBuilder.create();
                          sponserList = gson.fromJson(response.toString(),
                                  new TypeToken&lt;List&lt;Sponsors&gt;&gt;() {
                                  }.getType());
  
                          if (sponserList.size() &lt;= 0) {
                              tv = (TextView) findViewById(R.id.no_text);
                              tv.setVisibility(View.VISIBLE);
                              list2.setVisibility(View.GONE);
                              list.setVisibility(View.GONE);
                              mSwipeRefreshLayout.setEnabled(false);
                              mSwipeRefreshLayout2.setEnabled(false);
                              tv.setText(getResources().getString(R.string.spo_empty));
                          } else {
                              list2.setVisibility(View.VISIBLE);
                              list.setVisibility(View.GONE);
                              tv = (TextView) findViewById(R.id.no_text);
                              tv.setVisibility(View.GONE);
                              mSwipeRefreshLayout.setEnabled(false);
  
                              sponserAdapter = new SponsorsAdapter(MainScreenActivity.this, sponserList);
                              list2.setAdapter(sponserAdapter);
                              list2.requestLayout();
                              list2.smoothScrollToPosition(0);
                              sponserAdapter.notifyDataSetChanged();
  
  
                          }
  
  
                          list2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                              @Override
                              public void onItemClick(AdapterView&lt;?&gt; parent,
                                                      View view, int position, long id) {
                                  Intent i = new Intent(MainScreenActivity.this,
                                          SponsorDetailActivity.class);
                                  Bundle b = new Bundle();
                                  b.putString("user_id", sponserList.get(position)
                                          .getUser_id());
                                  b.putString("name", sponserList.get(position).getName());
                                  i.putExtras(b);
                                  startActivity(i);
                              }
                          });
  
  
                          mSwipeRefreshLayout2.setRefreshing(false);
                      } catch (NullPointerException e) {
                          e.printStackTrace();
                          mSwipeRefreshLayout2.setRefreshing(false);
                      } catch (IllegalStateException e) {
                          e.printStackTrace();
                      }
  
                      if (pDialog != null) {
                          pDialog.dismiss();
                      }
  
  
                  }
              });
  }
  </code></pre>
  
  <p>Please help me to solve this problem. Thank you.</p>