android - 如何获取上一个或下一个 View

标签 android view find next

如何获取SlideButton View 的上一个 View (TextView),以及SlideButton View 的下一个 View 。

ID 为“remotelight”的 SlideButton View 。我可以使用“findViewById”方法获取 SlideButton View 。 所以在我获得 SlideButton View 之后,如何在没有“findViewById”方法帮助的情况下获得上一个 View 和下一个 View 。

非常感谢。

下面是布局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>

最佳答案

您可以使用充当小部件容器的 ViewGroup 实例来执行此操作。

参见 getChildAt(int)indexOfChild(View)

因此 getChildAt(indexOfChild(v)+1) 将为您提供下一个 View 。

有点像

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

您应该添加溢出检查,并且下一个 View 是您实际想要的类型。

关于android - 如何获取上一个或下一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194823/

相关文章:

ruby-on-rails - 在嵌入式 ruby 中排序

java - 用于建模 View 的类

ffmpeg - 使用 ffmpeg 批量转换文件并找到 -exec 和并行

java - 有没有一种方法可以在 EditText 中连接不同的 Activity TextView?

android - 是否有事件可以检测屏幕何时变暗?

android - 使用启用了快速滚动的 ListView 时,如何更改字母弹出窗口的文本颜色?

java - Android:带有事件的日历

sql-server - 无法使用 SQL Server 中的用户定义函数在 View 上创建索引

linux - 'find/-name ' 文件的最大限制'-o -iname 'file2' -o -iname 'file3' ..."等

c++ - std::find 与从 vector 导出模板