开发者

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:orientatio开发者_开发问答n="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!


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜