Giả sử tôi có một xml bố trí đơn giản như sau:thổi phồng vs findViewById
button.xml:
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Có bất kỳ sự khác biệt trong các cuộc gọi sau đây? và tôi nên sử dụng cái nào?
button = (Button) getLayoutInflater().inflate(R.layout.button, null);
và
View v = getLayoutInflater().inflate(R.layout.button, null);
button = (Button) v.findViewById(R.id.button01);
Rất tiếc, nó lọc mã của tôi. ở đây: Nút \t xmlns: android = "http://schemas.android.com/apk/res/android" \t android: id = "@ + id/button01" \t android: layout_width = "wrap_content" \t android: layout_height = "wrap_content" –