Repository navigation
View Bindings
AssemblyJohn edited this page Oct 9, 2014
·
3 revisions
Why use View.setOnClickListener()? We have to add an extra line for that, add the callback, make a new listener(or if it is an inner class, have unnecessary indentation), we are directly dependent on the view etc...
Instead just do:
public class MainActivity extends InfuseActivity {
@BindOnClick(value = GetTextListener.class, id = R.id.buttonText)
private Button mGetText;
}The code below does exactly the same as the one above. We just have to be sure the view has at least one resource id, to search for the view.
public class MainActivity extends InfuseActivity {
@BindOnClick(GetTextListener.class)
@InfuseView(R.id.buttonText)
private Button mGetText;
}Need to bind more than a listener? No problem, use @BindAdapter for an adapter and @BindOnItemClick for the item click listener.
public class MainActivity extends InfuseActivity {
@BindAdapter(TestListAdapter.class)
@BindOnItemClick(ListListener.class)
@InfuseView(R.id.listView1)
private ListView mListView;
}Can also use the following notation, it is only a matter of preference. It is the same as the above:
public class MainActivity extends InfuseActivity {
@BindAdapter(value = TestListAdapter.class, id = R.id.listView1)
@BindOnItemClick(value = ListListener.class, id = R.id.listView1)
private ListView mListView;
}