为什么要定义自己的适配器呢,原因就在于,当我们想用一些其它的展现方式,或者是我们需要的,呈现方式,这是就得DIY了 首先我们定义一个类让它继承自BaseAdapter,再让它实现一里面所说的那几个方法。那么这个自定义适配器就算好了。 里面的一些方法我在上面都介绍过了,在这就不在赘述了。 public class NoteAdapter extendsBaseAdapter { private Context mcontext; }; //构造函数里面有两个参数,一个是数据的来源,另一个是上下文。 public NoteAdapter(Integer[] Ids,Context c){ mcontext=c; iIds=Ids; } publicint getCount() { // TODO Auto-generated method stub return imageIds.length; }
publicObject getItem(int position) { // TODO Auto-generated method stub return null; } publiclong getItemId(int position) { // TODO Auto-generated method stub return position; } //主要工作是做在这里,可以自定义布局,在这里我就不多说了 publicView getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView view = new TextView (mcontext); view .Text(Ids[position]); return view ; } }作者:唐如璇:原文地址