Activity.FindViewById 方法

定义

重载

FindViewById(Int32)

查找由在中#onCreate处理的 XML 属性标识的android:id视图。

FindViewById<T>(Int32)

查找由 XML 布局资源中的 ID 属性标识的视图。

FindViewById(Int32)

查找由在中#onCreate处理的 XML 属性标识的android:id视图。

[Android.Runtime.Register("findViewById", "(I)Landroid/view/View;", "GetFindViewById_IHandler")]
public virtual Android.Views.View? FindViewById (int id);
[<Android.Runtime.Register("findViewById", "(I)Landroid/view/View;", "GetFindViewById_IHandler")>]
abstract member FindViewById : int -> Android.Views.View
override this.FindViewById : int -> Android.Views.View

参数

id
Int32

要搜索的 ID

返回

如果找到,则为具有给定 ID 的视图,否则 null

属性

注解

查找由在中#onCreate处理的 XML 属性标识的android:id视图。

<strong Note:</strong>> 在大多数情况下 -- 根据编译器支持 - 生成的视图会自动强制转换为目标类类型。 如果目标类类型不受约束,则可能需要显式强制转换。

适用于 . 的 android.app.Activity.findViewById(int)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于

FindViewById<T>(Int32)

查找由 XML 布局资源中的 ID 属性标识的视图。

public T? FindViewById<T> (int id) where T : Android.Views.View;
member this.FindViewById : int -> 'T (requires 'T :> Android.Views.View)

类型参数

T

要返回的视图的类型(Button、ListView 等)。

参数

id
Int32

要查找的视图的 ID。

返回

T

如果找到或为 null,则为视图。

注解

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于