how can I get the previous view(TextView) of the SlideButton view, and the next view of the SlideButton view.
The SlideButton view with the id "remotelight". I can get the SlideButton view with the method "findViewById". so after I get the SlideButton View, how can I get the previous view and the next view ,without the help of "findViewById" method.
thanks so much.
below is a part of layout xml:
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<com.ivn.SlideButton
android:id="@+id/remotelight"
android:layout_width="100dp"
android:layout_height="50dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
I created two functions that put @CjS solution into use:
You can use the
ViewGroup
instance that's acting as a container for your widgets to do this.See getChildAt(int) and indexOfChild(View)
So
getChildAt(indexOfChild(v)+1)
will get you the next view.So something like
You should add checks for overflow and that the next view is of the type that you do in fact want.