I have a layout with a scrollview and a relative layout inside of the scrollview. I have toggle buttons radio groups and edittext inside this scrollview. The issue I am having is that when I start scrolling down and selecting the toggle buttons, after selection the screen scrolls up automatically to the top. Why is this happening?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/grad_col_bk"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.91"
android:background="@color/darker_grey" >
<RelativeLayout
android:id="@+id/main_rel_search_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ToggleButton
android:id="@+id/salinityToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textOff="Salinity"
android:textOn="Salinity " />
<RadioGroup
android:id="@+id/radgroupsal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/salinityToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/salGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedSalinityGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/salLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedSalinityLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/salabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupsal"
android:background="@android:color/white" />
<EditText
android:id="@+id/salinityValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/salinityToggleButton"
android:layout_alignBottom="@+id/salinityToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<ToggleButton
android:id="@+id/AmmoniaToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/salabove"
android:textOff="Ammonia"
android:textOn="Ammonia " />
<EditText
android:id="@+id/ammoniaSearchNumber"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/AmmoniaToggleButton"
android:layout_alignBottom="@+id/AmmoniaToggleButton"
android:layout_alignRight="@+id/salinityValue"
android:background="@android:color/white"
android:ems="10"
android:inputType="numberDecimal"
android:paddingLeft="8dp" >
</EditText>
<RadioGroup
android:id="@+id/radgroupamm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/AmmoniaToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/ammGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedAmmoniaGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/ammLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedAmmoniaLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/ammabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupamm"
android:background="@android:color/white" />
<!-- split below is nitrite -->
<ToggleButton
android:id="@+id/NitriteToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/ammabove"
android:textOff="Nitrite"
android:textOn="Nitrite " />
<EditText
android:id="@+id/nitriteValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/NitriteToggleButton"
android:layout_alignBottom="@+id/NitriteToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupnitri"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/NitriteToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/nitriGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedNitriteGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/nitriLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedNitriteLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/nitriabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupnitri"
android:background="@android:color/white" />
<!-- Nitrate Below -->
<ToggleButton
android:id="@+id/NitrateToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/nitriabove"
android:textOff="Nitrate"
android:textOn="Nitrate " />
<EditText
android:id="@+id/nitrateValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/NitrateToggleButton"
android:layout_alignBottom="@+id/NitrateToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupnitra"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/NitrateToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/nitraGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedNitrateGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/nitraLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedNitrateLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/nitraabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupnitra"
android:background="@android:color/white" />
<!-- pH Below -->
<ToggleButton
android:id="@+id/phToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/nitraabove"
android:textOff="pH"
android:textOn="pH " />
<EditText
android:id="@+id/phValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/phToggleButton"
android:layout_alignBottom="@+id/phToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupph"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/phToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/phGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedPhGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/phLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedPhLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/phabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupph"
android:background="@android:color/white" />
<!-- Calcium Below -->
<ToggleButton
android:id="@+id/calciumToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/phabove"
android:textOff="Calcium"
android:textOn="Calcium " />
<EditText
android:id="@+id/calciumValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/calciumToggleButton"
android:layout_alignBottom="@+id/calciumToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupcalcium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/calciumToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/calciumGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedCalciumGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/calciumLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedCaliumLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/calciumabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupcalcium"
android:background="@android:color/white" />
<!-- Phosphate Below -->
<ToggleButton
android:id="@+id/phosphateToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/calciumabove"
android:textOff="Phosphate"
android:textOn="Phosphate " />
<EditText
android:id="@+id/phosValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/phosphateToggleButton"
android:layout_alignBottom="@+id/phosphateToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupphosphate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/phosphateToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/phosphateGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedPhosphateGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/phosphateLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedPhosphateLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/phosphateabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupphosphate"
android:background="@android:color/white" />
<!-- temperature below -->
<ToggleButton
android:id="@+id/temperatureToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/phosphateabove"
android:textOff="Temperature"
android:textOn="Temperature " />
<EditText
android:id="@+id/temperatureValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/temperatureToggleButton"
android:layout_alignBottom="@+id/temperatureToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgrouptemperature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/temperatureToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/temperatureGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedTemperatureGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/TemperatureLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedTemperatureLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/temperatureabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgrouptemperature"
android:background="@android:color/white" />
<!-- Alkalinity Below -->
<ToggleButton
android:id="@+id/alkalinityToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/temperatureabove"
android:textOff="Alkalinity"
android:textOn="Alkalinity " />
<EditText
android:id="@+id/AlkalinityValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/alkalinityToggleButton"
android:layout_alignBottom="@+id/alkalinityToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupalkalinity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/alkalinityToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/alkalinityGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedAlkalinityGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/AlkalinityLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedAlkalinityLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/alkalinityabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupalkalinity"
android:background="@android:color/white" />
<!-- Magnesium Below -->
<ToggleButton
android:id="@+id/magnesiumToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/alkalinityabove"
android:textOff="Magnesium"
android:textOn="Magnesium " />
<EditText
android:id="@+id/MagnesiumValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/magnesiumToggleButton"
android:layout_alignBottom="@+id/magnesiumToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupmagnesium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/magnesiumToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/magnesiumGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedMagnesiumGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/MagnesiumLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedMagnesiumLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/magnesiumabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupmagnesium"
android:background="@android:color/white" />
<!-- TDS below -->
<ToggleButton
android:id="@+id/tdsToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/magnesiumabove"
android:textOff="TDS"
android:textOn="TDS " />
<EditText
android:id="@+id/tdsValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/tdsToggleButton"
android:layout_alignBottom="@+id/tdsToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgrouptds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tdsToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/tdsGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedTdsGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/tdsLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedTdsLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/tdsabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgrouptds"
android:background="@android:color/white" />
<!-- Iodine below -->
<ToggleButton
android:id="@+id/iodineToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tdsabove"
android:textOff="Iodine"
android:textOn="Iodine " />
<EditText
android:id="@+id/iodineValue"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/iodineToggleButton"
android:layout_alignBottom="@+id/iodineToggleButton"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@color/white"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<RadioGroup
android:id="@+id/radgroupiodine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iodineToggleButton"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/iodineGreat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedIodineGreater"
android:text="Greater Than" />
<RadioButton
android:id="@+id/iodineLess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:onClick="onRadioButtonClickedIodineLess"
android:text="Less Than" />
</RadioGroup>
<View
android:id="@+id/iodineabove"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/radgroupiodine"
android:background="@android:color/white" />
<!-- Search button below -->
<Button
android:id="@+id/searchButton"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignTop="@+id/iodineabove"
android:text="Search" />
</RelativeLayout>
</ScrollView>
This happens because one of the views on top takes focus. Just add
android:focusableInTouchMode="true"
to the child of your ScrollView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With