0

I have HorizontalScrollView , Which has a Horizontal Linear layout with 7 chips. In which some chips are out of screen.

Selected chipID is stored in DataStore (branchTypeID)

So now the next time this view(BottomSheetDialog) is created. I want to have auto scrolled to the position of the selected chip

But ,next time the chip Group View is created, it starts from the beginning . The selected chip is off the screen.Then manual scrolling is required. Which i want to avoid.

xml is as follows

<HorizontalScrollView
            android:id="@+id/branches_scrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/branches_linearLayout"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <com.google.android.material.chip.ChipGroup
                    android:id="@+id/branchType_chipGroup"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:checkedChip="@+id/cs_chip"
                    app:selectionRequired="true"
                    app:singleLine="false"
                    app:singleSelection="true">

                    <com.google.android.material.chip.Chip
                        android:id="@+id/cs_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <com.google.android.material.chip.Chip
                        android:id="@+id/ec_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <com.google.android.material.chip.Chip
                        android:id="@+id/ee_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                    <com.google.android.material.chip.Chip
                        android:id="@+id/mech_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                    <com.google.android.material.chip.Chip
                        android:id="@+id/civil_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <com.google.android.material.chip.Chip
                        android:id="@+id/ch_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                    <com.google.android.material.chip.Chip
                        android:id="@+id/oth_chip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>


                </com.google.android.material.chip.ChipGroup>
            </LinearLayout>
        </HorizontalScrollView>

In the program

    val chip = mView.branchType_chipGroup.findViewById<Chip>(branchTypeId)
    if (chip != null)
        mView.branches_scrollView.scrollTo(chip.left, chip.right)

The above code is not working

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
  • If all of the chips are displayed on the screen, i.e., there is nothing to scroll then you won't see any scrolling. Are any chips off the screen? When you say "not working", what precisely do you mean? Does nothing happen or does it scroll to the wrong place? In the actual layout, do any views appear before the chip group? – Cheticamp Jan 04 '22 at 18:41
  • 1
    There are chips which goes off the screen, and the chips which are selected off the screen,are not seen in the view. So I want to scroll to the selected view. – krishnaacharyaa Jan 04 '22 at 19:51
  • 1
    @Cheticamp Please find the updated question above! – krishnaacharyaa Jan 04 '22 at 20:06

0 Answers0