title: Android getting Only the original thread that created error with useing listerner again
body: <p>In simple part of my application i connect to internet to getting data from server, for managing original thread i use simple interface as listener to send data after fetch from server to main thread, but i get this error again:</p>
  
  <pre><code>Only the original thread that created a view hierarchy can touch its views
  </code></pre>
  
  <p><strong>my listener:</strong></p>
  
  <pre><code>public void getProductData(OnGettingProducts listener) {
      onGettingProducts = listener;
  }
  
  public interface OnGettingProducts {
      void onProducts(String data);
  }
  </code></pre>
  
  <p><strong>my thread:</strong></p>
  
  <pre><code>new Thread() {
      @Override
      public void run() {
  
          String parseUrl = ".....";
  
          String data = getJSON(parseUrl);
          if (onGettingProducts != null) {
              onGettingProducts.onProducts(data);
          }
      }
  }.start();
  </code></pre>
  
  <p>listener on main thread as <code>All_Products</code> fragment:</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
  
      ...
  
      getProductData(new OnGettingProducts() {
          @Override
          public void onProducts(String data) {
              Gson converter = new Gson();
  
              Type type = new TypeToken&lt;List&lt;ProductDetails&gt;&gt;() {
              }.getType();
              List&lt;ProductDetails&gt; list = converter.fromJson(data, type);
  
              addProducts(list);
          }
      });
  
      return mView;
  }
  </code></pre>
  
  <p><strong>and <code>addProducts</code> method to update adapter:</strong></p>
  
  <pre><code>private void addProducts(List&lt;ProductDetails&gt; products) {
      if (products.size() &gt; 0) {
          productsList.addAll(products);
  
          for (int i = 0; i &lt; products.size(); i++) {
              if (products.get(i).getStatus() != null &amp;&amp; !"publish".equalsIgnoreCase(products.get(i).getStatus())) {
                  for (int j = 0; j &lt; productsList.size(); j++) {
                      if (products.get(i).getId() == productsList.get(j).getId()) {
                          productsList.remove(j);
                      }
                  }
              }
          }
      }
  
      productAdapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
      at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7905)
      at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1276)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.support.v4.widget.DrawerLayout.requestLayout(DrawerLayout.java:1303)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.view.View.requestLayout(View.java:22139)
      at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
      at android.view.View.requestLayout(View.java:22139)
      at android.support.v7.widget.RecyclerView.requestLayout(RecyclerView.java:4202)
      at android.support.v7.widget.RecyclerView$RecyclerViewDataObserver.onChanged(RecyclerView.java:5286)
      at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyChanged(RecyclerView.java:11997)
      at android.support.v7.widget.RecyclerView$Adapter.notifyDataSetChanged(RecyclerView.java:7070)
      at com.vectorcoder.androidwoocommerce.fragments.All_Products.addProducts(All_Products.java:423)
      at com.vectorcoder.androidwoocommerce.fragments.All_Products.access$000(All_Products.java:69)
      at com.vectorcoder.androidwoocommerce.fragments.All_Products$1.onProducts(All_Products.java:157)
      at com.vectorcoder.androidwoocommerce.fragments.All_Products$10.run(All_Products.java:617)
  </code></pre>