Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return the index of child in Layout?

I have the following situation - HorizontalScrollView (HSV), inside HSV - LinearLayout and inside it number of buttons - the code is here:

<HorizontalScrollView
        android:id="@+id/Footer"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5"
        android:background="@drawable/footer_bg"
        android:scrollbars="none"
        android:fadingEdge="none"
        >

        <LinearLayout
            android:id="@+id/hsvLinearLayout"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

            <Button
                android:id="@+id/today"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/today"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/today"
                android:onClick="getRSSNews"
                />

            <Button
                android:id="@+id/life"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/life"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/life"
                android:onClick="getRSSNews"
                />

            <Button
                android:id="@+id/corner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/corner"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/corner"
                android:onClick="getRSSNews"
                />

            <Button
                android:id="@+id/banks"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/banks"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/banks"
                android:onClick="getRSSNews"
                />

            <Button
                android:id="@+id/it"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/it"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/it"
                android:onClick="getRSSNews"
                />

            <Button
                android:id="@+id/fun"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableTop="@drawable/fun"
                android:drawablePadding="0sp"
                android:gravity="center_horizontal|bottom"
                android:textSize="8sp"
                android:text="@string/fun"
                android:onClick="getRSSNews"
                />

        </LinearLayout>

    </HorizontalScrollView>

Is there a way to get the position(index) of the button, on which has been clicked!

like image 895
nenito Avatar asked Sep 12 '25 13:09

nenito


2 Answers

indexOfChild returns the position in the group of the specified child view.

like image 187
xevincent Avatar answered Sep 14 '25 02:09

xevincent


You may give tag to each view and check the tag when that view is clicked.This may help you.

like image 39
Pooja M. Bohora Avatar answered Sep 14 '25 04:09

Pooja M. Bohora