title: Dynamic button display programmatically Android
body: <p>I want to add buttons programmatically on the screen and I am getting the value by parsing an <code>API</code> and now I want to display the buttons according to the length of an array. I am doing this but I am only getting the last button displayed, but inside the <code>for</code> loop I'm getting all values correct but displaying only the last button. This is my code: </p>
  
  <pre><code>RelativeLayout relate;
  
  //...
  relate = (RelativeLayout)findViewById(R.id.relative);
  
  protected void onPostExecute(Void result) {
      if(dialog.isShowing() == true) {
          dialog.dismiss();
      }
  
      //int width = 100, height =50, x = 10, y = 20;
  
      for (int i =0;i&lt;adapt_obj.city_name_array.length;i++){
          b1 = new Button(myref);
  
          b1.setText(adapt_obj.city_name_array[i]);
  
          relate.addView(b1);
  
          //relate.addView(b1, i,  new RelativeLayout.LayoutParams(width,height));
  
          //height = height+80;
      }
  
      listlocation.setAdapter(adapt_obj);
      adapt_obj.notifyDataSetChanged();
  }
  </code></pre>