android findViewById疑惑

<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基础知识。


猜你喜欢

转载自blog.csdn.net/ichangemy/article/details/78737055