Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created September 7, 2011 16:01
Show Gist options
  • Save rsaunders100/1200971 to your computer and use it in GitHub Desktop.
Save rsaunders100/1200971 to your computer and use it in GitHub Desktop.
(Android) Example code for a simple array adaptor.
public class ExampleAdapter extends ArrayAdapter<String> {
private LayoutInflater _inflater;
//
// Initialize the adaptor with an Array List of items to display.
//
public ExampleAdapter(Context context, ArrayList<String> strings)
{
super(context, R.layout.example_row, strings);
_inflater = LayoutInflater.from(context);
}
//
// This method returns a row of the list view to display at a given index
//
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// If we cant re-use an existing row, create one from the layout inflator
if (convertView == null)
{
convertView = _inflater.inflate(R.layout.example_row, null);
}
// Grab info from the array list and insert it into the row.
String name = getItem(position);
TextView nameLabel = (TextView)convertView.findViewById(R.id.example_name_label);
nameLabel.setText(name);
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment