語言

Window.FindViewById 方法

定義

多載

名稱 Description
FindViewById(Int32)

找到一個由 android:id XML 屬性識別的檢視,該屬性在 android.app.Activity#onCreate中被處理。

FindViewById<T>(Int32)

找到以指定 ID 作為請求型別的檢視。

FindViewById(Int32)

找到一個由 android:id XML 屬性識別的檢視,該屬性在 android.app.Activity#onCreate中被處理。

[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 方式

屬性

備註

找到一個由 android:id XML 屬性識別的檢視,該屬性在 android.app.Activity#onCreate中被處理。

這會 #getDecorView 隱含所有相關的副作用。

<strong>注意:</strong> 大多數情況下——視編譯器支援而定——結果的視圖會自動投射為目標類別類型。 若目標類別類型不受限制,則可能需要明確施放。

Java 文件 android.view.Window.findViewById(int)。

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

FindViewById<T>(Int32)

找到以指定 ID 作為請求型別的檢視。

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

類型參數

T

那種預期的視角。

參數

id
Int32

要查找的視圖資源識別碼。

傳回

T

匹配視圖為 T,或 null 當沒有 與 的 id 視角存在時。

備註

這種管理便利過載執行與非通用過載相同的搜尋。 只有當沒有 與 的id視圖不存在時,它才會返回;當無法將匹配的視圖投射到 T時,它會InvalidCastException拋null出。

適用於