This problem has been asked many times here, but none of the solutions work for me, because my XML layout is a bit different.
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 here, it lists the files and folders that exists in the android filesystem.
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<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" />
<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" />
</LinearLayout>
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.
What I want is similar to the image in this post, but cannot achieve it till now. None of those solutions or any other that I read here works in my case.
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.
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);
Please guide me what am I doing wrong, and how to make it possible.
Regards.