Skip to content

Instantly share code, notes, and snippets.

@brindy
Created May 6, 2009 20:20
Show Gist options
  • Save brindy/107718 to your computer and use it in GitHub Desktop.
Save brindy/107718 to your computer and use it in GitHub Desktop.
A sample custom ListAdapter for Android
setListAdapter(new BaseAdapter() {
public int getCount() {
return expenses.size();
}
public Object getItem(int position) {
return expenses.get(position);
}
public long getItemId(int position) {
Expense expense = expenses.get(position);
return expense.getId();
}
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(getClass().getName(), "getView()");
Expense exp = expenses.get(position);
View view = View.inflate(context, R.layout.expenses_row, null);
TextView value = (TextView) view.findViewById(R.id.value);
value.setText(mDecimalFormat.format(exp.getValue()));
TextView desc = (TextView) view.findViewById(R.id.description);
desc.setText(exp.getDescription());
return view;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment