Created
September 7, 2011 16:01
-
-
Save rsaunders100/1200971 to your computer and use it in GitHub Desktop.
(Android) Example code for a simple array adaptor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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