title: addView button from AsyncTask class, no error but button not showing
body: <p>Semi-new to programming Android apps, or apps in general.  I'm trying to create a bunch of buttons based on JSON response.  The response is coming back good (checked in Log.i) and no errors showing an issue, but the buttons aren't displaying.  Here's my main activity, asynctask class and main xml.  Any feedback super appreciated.</p>
  
  <p>Main Activity:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      Spinner spinner;
      public SpinAdapter adapter;
      JSONObject jsonobject;
      JSONArray jsonarray;
      ProgressDialog mProgressDialog;
      ArrayList&lt;String&gt; barlist;
      Brewery[] breweries;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          spinner = (Spinner) findViewById(R.id.planets_spinner);
          Log.i("msg", "sent to json");
          new DownloadJSON().execute();
          Log.i("msg", "past to json");
      }
  
      private class DownloadJSON extends AsyncTask&lt;Void, Void, Void&gt; 
      {
  
          @Override
          protected Void doInBackground(Void... params) {
  
          barlist = new ArrayList&lt;String&gt;();
          try
          {
              Log.i("msg", "inside try");
              HttpClient httpclient = new DefaultHttpClient();
              httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
              HttpGet request = new HttpGet("http://fltapmap.com/populate.php");
              HttpResponse response = httpclient.execute(request);
              HttpEntity resEntity = response.getEntity();
  
              String _response=EntityUtils.toString(resEntity); 
              jsonobject = new JSONObject(_response); 
              jsonarray = jsonobject.getJSONArray("breweries");
              Log.i("msg", "breweries lengths: "+jsonarray.length());
              breweries = new Brewery[jsonarray.length()];
              for (int i = 0; i &lt; jsonarray.length(); i++) {
                  jsonobject = jsonarray.getJSONObject(i);
                  breweries[i] = new Brewery();
                  breweries[i].setId(jsonobject.optInt("ID"));
                  breweries[i].setName(jsonobject.optString("brewery"));
              }
          }catch(Exception e)
          {
              Log.i("msg",""+e.getMessage());
  
          }
          return null;
  
          }
          protected void onPostExecute(Void args) {
              // Spinner adapter
              adapter = new SpinAdapter(MainActivity.this,android.R.layout.simple_spinner_item,breweries);
              spinner.setAdapter(adapter);
  
              // You can create an anonymous listener to handle the event when is selected an spinner item
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                  @Override
                  public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view,
                          int position, long id) {
                      // Here you get the current item (a User object) that is selected by its position
                      Brewery brewery = adapter.getItem(position);
                      // Here you can do the action you want to...
                      Log.i("msg", "inside selected method"+String.valueOf(brewery.getId()));
  
                      new RetrieveBeersTask(MainActivity.this, findViewById(R.id.beer_list)).execute(String.valueOf(brewery.getId()));
                      /*
                      jsonarray = jsonobject.getJSONArray("ontap");
                      Log.i("msg", "breweries lengths: "+jsonarray.length());
                      Button beer_btns[] = new Button[jsonarray.length()];
                      Log.i("msg","buttons made");
  
                      for (int i = 0; i &lt; jsonarray.length(); i++) {
                          Log.i("msg","in loop"+String.valueOf(i));
                          LinearLayout layout = (LinearLayout)findViewById(R.id.beer_list);
  
                          beer_btns[i] = new Button(MainActivity.this);
  
                          beer_btns[i].setText(jsonarray.getJSONObject(i).getString("beer"));
  
                          beer_btns[i].setGravity(Gravity.CENTER_HORIZONTAL);
  
                          beer_btns[i].setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View v) {
                                  //add your code here 
                              }
                          });
                          layout.addView(beer_btns[i]);
                      }
                      */
                  }
                  @Override
                  public void onNothingSelected(AdapterView&lt;?&gt; adapter) {  }
              });
          }
     }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>AsyncTask Class</p>
  
  <pre><code>public class RetrieveBeersTask extends AsyncTask&lt;String, Void, ArrayList&lt;String&gt;&gt; {
  
      private Exception exception;
      JSONObject jsonobject;
      public JSONArray jsonarray;
      public ArrayList&lt;String&gt; return_beers;
      private Activity myMain;
      private View myLayout;
  
      public RetrieveBeersTask(Activity passedin, View mainLayout) {
          this.myMain = passedin;
          this.myLayout = mainLayout;
      }
  
      @Override
      protected ArrayList&lt;String&gt; doInBackground(String... brewery) {
          try {
              Log.i("msg", "inside launcher: Brewery - "+brewery[0]);
              HttpClient httpclient = new DefaultHttpClient();
              httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
              HttpGet request = new HttpGet("http://fltapmap.com/ontap.php?id="+brewery[0]);
              HttpResponse response = httpclient.execute(request);
              Log.i("msg","request back");
              HttpEntity resEntity = response.getEntity();
              String _response=EntityUtils.toString(resEntity);
  
              /*
              Log.i("msg","ssending request");
              HttpResponse response = httpclient.execute(request);
              Log.i("msg","request back");
              HttpEntity resEntity = response.getEntity();
              Log.i("msg","should have response");
              String _response=EntityUtils.toString(resEntity);
              Log.i("msg","got repsonse"+_response);
              */
              jsonobject = new JSONObject(_response); 
              jsonarray = jsonobject.getJSONArray("ontap");
  
              return_beers = new ArrayList&lt;String&gt;();
              for (int i = 0; i &lt; jsonarray.length(); i++) {
                  Log.i("msg", "beer name: "+jsonarray.getJSONObject(i).getString("beer"));
                  return_beers.add(jsonarray.getJSONObject(i).getString("beer"));
              }
              return return_beers;        
          } catch(Exception e) {
              e.printStackTrace();
              return null;        
          }            
      }
  
      protected void onPostExecute(ArrayList&lt;String&gt; beers) {
          // TODO: check this.exception 
          // TODO: do something with the feed
          Log.i("msg", "length of array: "+String.valueOf(beers.size()));
          Button beer_btns[] = new Button[jsonarray.length()];
          for (int i = 0; i &lt; beers.size(); i++) {
  
              beer_btns[i] = new Button(myMain);
  
              beer_btns[i].setText(beers.get(i));
  
              beer_btns[i].setGravity(Gravity.CENTER_HORIZONTAL);
  
              beer_btns[i].setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      //add your code here 
                  }
              });
              LinearLayout layout = (LinearLayout)myLayout;
              Log.i("msg",String.valueOf(layout));
              layout.addView(beer_btns[i]);
          }
      }
  }
  </code></pre>