title: Add Button to XML Layout programatically
body: <p>This problem has been asked many times here, but none of the solutions work for me, because my XML layout is a bit different.</p>
  
  <p>I have an XML with LinearLayout containing an ImageView and a TextView. The XML is populated using Java code. It is a file picker library from <a href="https://github.com/Kaloer/Android-File-Picker-Activity/blob/master/src/com/kaloer/filepicker/FilePickerActivity.java" rel="nofollow noreferrer">here</a>, it lists the files and folders that exists in the android filesystem.</p>
  
  <p>Here is the XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" 
      android:orientation="horizontal" &gt;
  
     &lt;ImageView
          android:id="@+id/file_picker_image"
          android:layout_width="40dip"
          android:layout_height="40dip"
          android:layout_marginBottom="5dip"
          android:layout_marginLeft="5dip"
          android:layout_marginTop="5dip"
          android:contentDescription="@string/app_name"
          android:scaleType="centerCrop"
          android:src="@drawable/file" /&gt;
  
      &lt;TextView
          android:id="@+id/file_picker_text"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dip"
          android:singleLine="true"
          android:text="@string/file_name"
          android:textSize="28sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Now, I want to add a button just below this list. When I try to add the button in the XML, it iterates though each row, and buttons are shown in every row.
  When I do it using Java code, neighter the button, nor the textview is displayed, but the image view is displayed.</p>
  
  <p>What I want is similar to the image in <a href="https://stackoverflow.com/questions/2383847/android-layout-with-listview-and-buttons">this</a> post, but cannot achieve it till now. None of those solutions or any other that I read here works in my case.</p>
  
  <p>I am trying to add the button using this code in the Activity whose source is in the link provided above. I tried to add the following code in FilePickerListAdapter's constructor.</p>
  
  <pre><code>            RelativeLayout relLayout = new RelativeLayout(context);
              RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
              params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  
              Button filterBtn = new Button(context);
              filterBtn.setText("Filter");
  
              relLayout.addView(filterBtn, params);
  </code></pre>
  
  <p>Please guide me what am I doing wrong, and how to make it possible.</p>
  
  <p>Regards.</p>