I have an xml file (option_element.xml) that contains a ImageView and a TextView
The inflate(int resource, ViewGroup root)
method return root
if root
is not null, thus to_add.findViewById()
equals options_layout.findViewById()
and it always return the Views in the first position.
Change as following should help:
LinearLayout options_layout = (LinearLayout) findViewById(R.id.options_list);
String[] options = getActivity().getResources().getStringArray(R.array.options);
for (int i = 0; i < options.length; i++) {
View to_add = inflater.inflate(R.layout.options_element,
options_layout);
TextView text = (TextView) to_add.findViewById(R.id.text);
text.setText(options[i]);
text.setTypeface(FontSelector.getBold(getActivity()));
}
to:
LinearLayout options_layout = (LinearLayout) findViewById(R.id.options_list);
String[] options = getActivity().getResources().getStringArray(R.array.options);
for (int i = 0; i < options.length; i++) {
View to_add = inflater.inflate(R.layout.options_element,
options_layout,false);
TextView text = (TextView) to_add.findViewById(R.id.text);
text.setText(options[i]);
text.setTypeface(FontSelector.getBold(getActivity()));
options_layout.addView(to_add);
}