forked from androidannotations/androidannotations
-
Notifications
You must be signed in to change notification settings - Fork 0
Adapters and lists
pyricau edited this page May 25, 2012
·
6 revisions
This is just a simple demonstration of how you could handle Adapters and AdapterViews in a simple way with AndroidAnnotations.
Let's say you have a Person class:
public class Person {
public final String firstName;
public final String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}and a PersonFinder interface:
public interface PersonFinder {
List<Person> findAll();
}You want to create a PersonListActivity that lists all the available persons. For that, you'll need a PersonListAdapter that creates the binds the data to the views, and a PersonItemView that is the view for one item in the list.
The PersonItemView will use one TextView for the first name, and one TextView for the last name:
@EViewGroup(R.layout.person_item)
public class PersonItemView extends LinearLayout {
@ViewById
TextView firstNameView;
@ViewById
TextView lastNameView;
public PersonItemView(Context context) {
super(context);
}
public PersonItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PersonItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void bind(Person person) {
firstNameView.setText(person.firstName);
lastNameView.setText(person.lastName);
}
}14/06/2012 The 2.6 release is out
- Get started!
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow