extends BaseAdapter
implements Filterable
A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.
However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list.
To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.
public ArrayAdapter (Context context, int resource, int textViewResourceId)
context The current context.
resource The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId The id of the TextView within the layout resource to be populated
public ArrayAdapter (Context context, int textViewResourceId, T[] objects)
context The current context.
textViewResourceId The resource ID for a layout file containing a TextView to use when instantiating views.
objects The objects to represent in the ListView.
public ArrayAdapter (Context context, int resource, int textViewResourceId, List<T> objects)
Constructor Parameters
context The current context.
resource The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId The id of the TextView within the layout resource to be populated
objects The objects to represent in the ListView.
一些常见的例子:
WordPress里面的例子:
需要学的的文件: moderateCommentsTab Preferences
1.用在 listView上
ArrayList<CharSequence> aBlogNames = new ArrayList<CharSequence>();
LayoutInflater inflater = (LayoutInflater)addAccount.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ListView lv = (ListView) inflater.inflate(R.layout.select_blogs_list, null);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setItemsCanFocus(false);
ArrayAdapter<CharSequence> blogs = new ArrayAdapter<CharSequence>(addAccount.this, R.layout.blogs_row, aBlogNames);
lv.setAdapter(blogs);
2.用在下拉框上
ArrayList<CharSequence> loadTextArray = new ArrayList<CharSequence>();
ArrayAdapter<CharSequence> categories = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_dropdown_item_1line, loadTextArray);
categories.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sCategories = (Spinner) findViewById(R.id.parent_category);
sCategories.setAdapter(categories);
3.又一个下拉框的例子:
final Spinner sInterval = new Spinner(this); sInterval.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); ArrayAdapter
http://blog.sina.com.cn/s/blog_541896910100q86v.html