android findViewById疑惑

来源:互联网 发布:天行健网络倒闭 编辑:程序博客网 时间:2024/05/01 22:47

<Button    android:id="@+id/register"    android:layout_width="0dp"    android:layout_height="wrap_content"    android:layout_weight="1"    android:layout_marginLeft="50dp"    android:layout_marginRight="20dp"    />

private Button but;

but=(Button)findViewById(R.id.register);


我之前一直在困惑,为什么要有一个强制类型转换,ID值明明就是Buttonde的,

今天懂了,因为findViewById()返回的是一个View类型的Id,这是java基础知识。


原创粉丝点击