Reputation: 10068
Something gone wrong on my code. I have an XML representing layout of my fragment (fragment_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
and another xml file representing a single view that shod go inside fragment layout (element.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<EditText
android:id="@+id/et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:inputType="number"
android:text="0" />
</RelativeLayout>
and this is how i fill Fragment layout inside onCreateView method:
View view = inflater.inflate(R.layout.fragment_layout, container,
false);
some_elements = getActivity().getResources().getStringArray(
R.array.some_array);
LinearLayout root = (LinearLayout) view.findViewById(R.id.root_layout);
for (int i = 0; i < some_elements.length; i++) {
View element = inflater.inflate(
R.layout.element, container, false);
TextView tv= (TextView) element.findViewById(R.id.tv);
prodotto.setText(prodotti[i]);
EditText et= (EditText) element.findViewById(R.id.et);
root.addView(element);
}
return view;
Now happen that only first element of "some_elements" array is showed inside fragment (element contains 10 elements). why other elements is not showed? what's wrong?
Upvotes: 3
Views: 3679
Reputation: 157447
The problem is android:layout_height="match_parent"
, in your RelativeLayout. It should be wrap_content
Upvotes: 3