※Adapter
·ArrayAdapter 使用泛型把Adapter视图绑定到一个指定类的对象的数组。使用一个对象数组的每个元素的toString值来填充指定布局中的TextView。
ArrayList<String> item = new ArrayList<>();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this,R.layout.item_list,item);
·SimpleAdapter
List<Map<String, String>> list;
list = new ArrayList<>();
Map<String, String> map;
map = new HashMap<>();
map.put("text", "item1");
list.add(map);
map = new HashMap<>();
map.put("text", "item2");
list.add(map);
SimpleAdapter simpleAdapter = new SimpleAdapter(getApplicationContext(), list, R.layout.item_list_view, new String[]{"text"}, new int[]{R.id.item_tv});
·SimpleCursorAdapter用于将一个Cursor绑定到一个AdapterView,并使用一个布局来定义每个行/条目的UI。每个行当视图的内容是底层Cursor中对应行的列值进行填充的。
String[] fromColums = new String[]{"str1","str2"};
int[] toLayoutIDs = new int[]{R.id.text1,R.id.text2};
SimpleCurosorAdapter myAdapter = new SimpleCursorAdapter(MainActivity.this,R.layout.item_simplecusor, cursor, fromColums, toLayoutIDs,flag);
·继承于BaseAdapter
public class MyAdapter extends BaseAdapter {
private List<ItemBean> list=new ArrayList<>();
static Context context;
private LayoutInflater inflater;
public MyAdapter(Context context,List<ItemBean> list) {
this.list = list;
this.context=context;
inflater=LayoutInflater.from(context);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=new ViewHolder();
if(convertView==null){
convertView=inflater.inflate(R.layout.item,null);
holder.iv=(ImageView) convertView.findViewById(R.id.imageview);
holder.title=(TextView) convertView.findViewById(R.id.title);
holder.time=(TextView) convertView.findViewById(R.id.time);
holder.content=(TextView) convertView.findViewById(R.id.content);
convertView.setTag(holder);
}
else{
holder=(ViewHolder) convertView.getTag();
}
ItemBean item=list.get(position);
holder.iv.setImageResource(item.getImageres());
holder.title.setText(item.getTitle());
holder.time.setText(item.getTime());
holder.content.setText(item.getContent());
return convertView;
}
class ViewHolder{
ImageView iv;
TextView title;
TextView time;
TextView content;
}
}