View.FindViewById Method

Definition

Overloads

Name Description
FindViewById(Int32)

Finds the first descendant view with the given ID, the view itself if the ID matches #getId(), or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

FindViewById<T>(Int32)

Finds the view with the specified ID as the requested type.

FindViewById(Int32)

Finds the first descendant view with the given ID, the view itself if the ID matches #getId(), or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

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

Parameters

id
Int32

the ID to search for

Returns

a view with given ID if found, or null otherwise

Attributes

Remarks

Finds the first descendant view with the given ID, the view itself if the ID matches #getId(), or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

<strong>Note:</strong> In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.

Java documentation for android.view.View.findViewById(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

FindViewById<T>(Int32)

Finds the view with the specified ID as the requested type.

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

Type Parameters

T

The expected view type.

Parameters

id
Int32

The resource identifier of the view to find.

Returns

T

The matching view as T, or null when no view with id exists.

Remarks

This managed convenience overload performs the same search as the non-generic overload. It returns null only when no view with id exists; it throws InvalidCastException when the matching view cannot be cast to T.

Applies to