Skip to content
AssemblyJohn edited this page Oct 14, 2014 · 5 revisions

An example with Infuse Factory for Android

Instead of writing a lot of boilerplate and initialization code, use a few @Binginds or @Infusions to get everything in place. Bind your listeners to your views, initialize your singletons without calling a lot of getInstance()'s, or just have your fields initialized without calling a single 'new'. And all in a 33kb lib!

public class MainActivity extends InfuseActivity {
	private static final String TAG = "MAIN_ACTIVITY";
	
	@BindAdapter(TestListAdapter.class)
	@BindOnItemClick(ListListener.class)
	@InfuseView(R.id.listView1)
	private ListView mListView;
	
	@BindOnClick(value = HideListener.class, id = R.id.buttonHide)
	private Button mHide;
	
	@InfuseView(R.id.textView1)
	private TextView mHelloWorld;
	
	@InfuseView(R.id.editText1)
	private EditText mText;
	
	@BindOnClick(value = GetTextListener.class, id = R.id.buttonText)
	private Button mGetText;
	
	@Infuse private DatabaseAdapter mDbAdapter;
	@Infuse private NetworkingAdapter mNetAdapter;
	@Infuse private PreferencesAdapter mPrefAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Log.d(TAG, "onCreate()");
	}
	
	@Override
	public void onContentChanged() {
		super.onContentChanged();
		
		Log.d(TAG, "onContentChanged");
		
		mHelloWorld.setText("Goodbye world!"); 
	}
}
Clone this wiki locally