FindViewbyid
时间: 2024-05-15 10:14:57 浏览: 12
FindViewById is a method used in Android development to find the view with a specific ID in the current hierarchy. It is used to get a reference to a view object so that it can be manipulated programmatically.
For example, if you have a TextView with an ID of "textView1" in your layout file, you can use the following code to get a reference to it:
```
TextView myTextView = (TextView) findViewById(R.id.textView1);
```
This code finds the view with the ID "textView1" and assigns it to the variable "myTextView". Once you have a reference to the view, you can manipulate its properties, such as setting its text or changing its visibility.
It's important to note that FindViewById can only be used after the view has been inflated, which typically happens in the onCreate() method of an Activity. If you try to use FindViewById before the view has been inflated, you'll get a null pointer exception.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)