首页 > 代码库 > baseAdapter

baseAdapter

public class MyAdapter extends BaseAdapter {    Context context;    public MyAdapter(Context context) {        this.context = context;    }    private CustomData[] data = http://www.mamicode.com/new CustomData[] {            new CustomData("name1", "dec1", R.drawable.img1),            new CustomData("name2", "dec2", R.drawable.img2),            new CustomData("name3", "dec3", R.drawable.img3) };    @Override    public View getView(int position, View convertView, ViewGroup parent) {        // TODO Auto-generated method stub        LinearLayout ls = null;        if (convertView != null) {            ls = (LinearLayout) convertView;        } else {            ls = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.custom, null);        }        CustomData data = getItem(position);        TextView  title = (TextView) ls.findViewById(R.id.title);        TextView dec = (TextView) ls.findViewById(R.id.dec);        ImageView Img = (ImageView) ls.findViewById(R.id.icon);                title.setText(data.title);        dec.setText(data.dec);        Img.setImageResource(data.iconID);            return ls;    }    @Override    public int getCount() {        // TODO Auto-generated method stub        return data.length;    }    @Override    public CustomData getItem(int position) {        // TODO Auto-generated method stub        return data[position];    }    @Override    public long getItemId(int position) {        // TODO Auto-generated method stub        return position;    }}