10.3.干掉findById
<LinearLayout ... >
<TextView android:id="@+id/name" />
<ImageView android:cropToPadding="true" />
<Button android:id="@+id/button" android:background="@drawable/rounded_button" />
</LinearLayout>你是否仍然使用findViewById查找view?
findViewById查找view?class ExampleActivity extends Activity {
private TextView tv;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_profile);
initView();
}
private void initView() {
tv = findViewById(R.id.name);
btn = findViewById(R.id.button);
}
}使用Butter Knife更优雅的查找view
view binding
Last updated