title: Android: Creating a ListView Adapter with an AsyncClass Object Array
body: <p>I need to store several different variables and then send them to a <code>ListView</code> <code>Adapter</code> as an Array so I can create custom rows. However, since the object that comes from the Array uses <code>AsyncTask</code> since I'm using <code>JSoup</code> and accessing the internet, I need a way to retrieve these variables in the Custom Adapter before I return the custom view back to the main class. Code is as follows:</p>
  
  <p><strong>ListView Adapter Code:</strong></p>
  
  <pre><code>public class CustomAdapter extends ArrayAdapter&lt;getProductAttributes&gt; implements OnCallCompleteCallBack{
  String title;
  String price;
  Bitmap image;
  
      //ArrayAdapter needs constructor, second parameter gets the layout for the list, third parameter is the array itself. "Context" always means background information.
      CustomAdapter(Context context, getProductAttributes[]items){
          super(context,R.layout.custom_row, items);
      }
  
      public void onCallComplete(int listSize, String title, String price, String imageSRC, String productURL){
           this.title=title;
           this.price = price;
           //Get Bitmap for image
           Bitmap mIcon11 = null;
              try {
                  InputStream in = new java.net.URL(imageSRC).openStream();
                  mIcon11 = BitmapFactory.decodeStream(in);
              } catch (Exception e) {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
           this.image=mIcon11;
      }
  
      @NonNull
      @Override
      public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
          LayoutInflater inflater = LayoutInflater.from(getContext());
          //One custom view is going to be equal to one row
          View customView = inflater.inflate(R.layout.custom_row,parent,false);
          ImageView productImage = (ImageView)customView.findViewById(R.id.imageView);
          TextView itemTitle = (TextView)customView.findViewById(R.id.itemTitle);
          TextView itemPrice = (TextView)customView.findViewById(R.id.itemPrice);
  
          productImage.setImageBitmap(image);
          itemTitle.setText(title);
          itemPrice.setText(price);
          return customView;
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>getProductAttributes class that extends AsyncTask:</strong></p>
  
  <pre><code>public class getProductAttributes extends AsyncTask&lt;Object, Object, Void&gt; {
      OnCallCompleteCallBack callback;
      String url;
      int index;
      String productURL;
      private String price;
      private String title;
      private String imageSRC;
      ImageView productView;
      int listSize;
      int result;
  
  public getProductAttributes(String url, int index, OnCallCompleteCallBack callback) {
      this.url = url;
      this.index = index;
      this.callback = callback;
  }
  
  protected Void doInBackground(Object... voids) {
      try{ 
        (code that gets all of the attributes, I'm sure that this code is working fine)
         }catch(Exception e){}
  
       return null;
      }
  
  protected void onPostExecute(Void aVoid) {
          super.onPostExecute(aVoid);
          if (callback != null) {
              callback.onCallComplete(listSize,title,price,imageSRC,productURL);
  
          }
      }
  </code></pre>
  
  <p>I think that the problem seems to be that by the time I run <code>onCallComplete</code> in the <code>CustomAdapter</code>, the customView has already been returned. If this is the case, what can I do to circumvent this?</p>
  
  <p>Thanks for your time and help! </p>