Search code examples
androidandroid-scrollview

How can I use scroll view on these checkboxes


I have about 10 check boxes and I can't go up or down to see all of them. How would I use scrollview to view them here's the xml for checkboxes.

`

<CheckBox
    android:id="@+id/CheckBox15"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />


<CheckBox
    android:id="@+id/CheckBox14"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </LinearLayout>


<CheckBox
    android:id="@+id/CheckBox13"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />


<CheckBox
    android:id="@+id/CheckBox12"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />


<CheckBox
    android:id="@+id/CheckBox11"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />


<CheckBox
    android:id="@+id/CheckBox10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />

 </LinearLayout>

` I want to use scroll view on this checkbox list please helping.


Solution

  • A ScrollView can only contain a single View or Layout, so put your LinearLayout inside the ScrollView, then put the checkboxes inside that LinearLayout:

    <ScrollView>
    <LinearLayout>
      <CheckBox />
      <CheckBox />
      <CheckBox />
      ....
    </LinearLayout>
    </ScrollView>