I have an ExpandableListView. The xml for the Child rows looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/number_input_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="right"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/temp_txt" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/number_input_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="right"
android:inputType="numberDecimal" />
<Spinner
android:id="@+id/spinner_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Basically, my getChildView looks like this:
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.list_item_child, viewGroup, false);
}
Spinner spinner = (Spinner) view.findViewById(R.id.spinner_1);
spinner.setAdapter(mUnitsCA);
spinner.setSelection(14); // 14 is a test
spinner.setOnItemSelectedListener(mSpinnerListener);
return view;
}
This should ensure that item number 14 in spinner_1 is selected every time. Some of the time this works, but often it selects the first item in the spinner instead. I can’t work out where this is happening. Any ideas?
One recommendation I found was to change
setSelection()to the following:Edit: (Building upon my answer for future seekers)
The documentation seems to be very vague on this, simply stating the following:
In my research it seems that many have had the same issues and from what I can tell declaring the animation
booleanseems to be necessary more often then not, whether it be true or false. Maybe only custom animations or declared animation’s require abooleanvalue oftruein order to animate but not having an animation will accept eithertrueorfalse…