关于findViewById
来源:互联网 发布:找人设计淘宝店多少钱 编辑:程序博客网 时间:2024/05/16 01:26
android.app.Activity中
public View findViewById (int id)
Since: API Level 1
Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
Returns
* The view if found or null otherwise.
public View findViewById (int id)
Since: API Level 1
Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
Returns
* The view if found or null otherwise.
这里的findViewById是在当前Active的View根及其儿子中通过Id寻找View
Active的View根一般是在其在onCreate函数中可以通过setContentView(R.layout.main)这种形式来设置。
android.view.View中
public final View findViewById (int id)
Since: API Level 1
Look for a child view with the given id. If this view has the given id, return this view.
Parameters
id The id to search for.
Returns
* The view that has the given id in the hierarchy or null
因为是findViewById在是从View及其儿子中查找,所以即使几个layout的XML文件中的View的id号相同的话,只要他们没有相同的父节点,或有相同的父亲节点,但不在父节点及以上节点调用findViewById通过id来查找他们就是没有问题。
Active的View根一般是在其在onCreate函数中可以通过setContentView(R.layout.main)这种形式来设置。
android.view.View中
public final View findViewById (int id)
Since: API Level 1
Look for a child view with the given id. If this view has the given id, return this view.
Parameters
id The id to search for.
Returns
* The view that has the given id in the hierarchy or null
因为是findViewById在是从View及其儿子中查找,所以即使几个layout的XML文件中的View的id号相同的话,只要他们没有相同的父节点,或有相同的父亲节点,但不在父节点及以上节点调用findViewById通过id来查找他们就是没有问题。
一般我都是在layout的XML文件中设置View的id。
比如:
<TextView
android:id="@+id/lable2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:editable="false"/>
<View android:id="@+id/View01" android:layout_width="wrap_content" android:layout_height="wrap_content"></View>
比如:
<TextView
android:id="@+id/lable2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:editable="false"/>
<View android:id="@+id/View01" android:layout_width="wrap_content" android:layout_height="wrap_content"></View>
- 关于findViewById
- 关于findviewbyid
- 关于findViewById函数
- 关于findViewByid的简写
- android findviewByid()关于空指针
- FindViewById
- findViewById
- findViewById
- findViewById
- findViewById
- findViewById
- 关于android findViewById 返回为空问题
- 初学Android—关于findViewById函数
- 关于findViewById你所不知道的
- android新手上路(二)--- 关于findViewById 返回为空
- 关于在adapter使用LinearLayout的findviewbyid问题
- 关于通过注解反射实现findViewById(int x);的原理
- 关于 findViewById()方法和资源 ID 的重复问题
- 嵌入式系统开发学习步骤(Linux高级编程学习顺序)(zz)
- C语言:内存字节对齐详解[转载]
- 系统地学习Linux (zz)
- 牛仔们的伦理:华尔街可以借鉴的西部行为守则
- c语言中结构体的大小和内存对齐问题
- 关于findViewById
- javascript图片360°旋转
- 未来GUI及其应用的研究(1) -- 基本的策略
- Silverlight4入门之rectangle控件(四)
- printk 工作原理
- MySQL数据库的引擎快速指导
- 今天学习了关于C++ 中可变参数个数函数的使用!
- 1
- Android传感器的环境监控