-
Notifications
You must be signed in to change notification settings - Fork 0
View Infusion
AssemblyJohn edited this page Oct 9, 2014
·
5 revisions
View infusion is quite simple. Instead of using findViewById()
and cast the returned object to the desired type just use @InfuseView
with the desired resource id.
All you have to do is to extend InfuseActivity
.
public class MainActivity extends InfuseActivity {
@InfuseView(R.id.textView1)
private TextView mHelloWorld;
@InfuseView(R.id.textView2)
private TextView mView1;
@InfuseView(R.id.textView3)
private TextView mView2;
@InfuseView(R.id.textView4)
private TextView mView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onContentChanged() {
super.onContentChanged();
mHelloWorld.setText("Goodbye world!");
}
}
Without view infusion:
public class MainActivity extends InfuseActivity {
private TextView mHelloWorld;
private TextView mView1;
private TextView mView2;
private TextView mView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mView1 = (TextView) findViewById(R.id.textView2);
mView2 = (TextView) findViewById(R.id.textView3);
mView3 = (TextView) findViewById(R.id.textView4);
mHelloWorld = (TextView) findViewById(R.id.textView1);
mHelloWorld.setText("Goodbye world!");
}
}