首页 > 代码库 > 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; }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。