如何获得previous或下一个视图 [英] How to get the previous or next view

查看:214
本文介绍了如何获得previous或下一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以得到previous鉴于SlideButton视图(TextView的),以及SlideButton视图的下一个视图。

该SlideButton视图id为remotelight。我可以与方法findViewById的SlideButton视图。
所以以后我得到的SlideButton视图,我怎么能得到previous视图和下一个视图,没有findViewById方法的帮助。

感谢这么多。

下面是布局的xml的一部分:

 <的TableRow
    机器人:ID =@ + ID / tableRow1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=/>    < com.ivn.SlideButton
        机器人:ID =@ + ID / remotelight
        机器人:layout_width =100dp
        机器人:layout_height =50dp/>
    <的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=/>< /&的TableRow GT;


解决方案

您可以使用的演技为您的小部件做这个容器中的的ViewGroup 实例。

请参阅getChildAt(int)
<一href=\"http://developer.android.com/reference/android/view/ViewGroup.html#indexOfChild%28android.view.View%29\">indexOfChild(View)

所以 getChildAt(indexOfChild(五)+1)将让你下一个视图。

因此​​,像

 的ViewGroup容器=(ViewGroup中)findViewbyID(R.tableRow1);
 查看slideBtn = findViewbyID(R.remoteLight);
 查看新思维= container.getChildAt(container.indexOfChild(slideBtn)+1);

您应该添加检查溢出,并认为,未来的看法是,你是想要做的类型。

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>

解决方案

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

 ViewGroup container = (ViewGroup) findViewbyID(R.tableRow1);
 View slideBtn = findViewbyID(R.remoteLight);
 View nextView = container.getChildAt(container.indexOfChild(slideBtn)+1);

You should add checks for overflow and that the next view is of the type that you do in fact want.

这篇关于如何获得previous或下一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆