首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android 中如何自定义个适配器

2012-04-23 
android 中怎么自定义个适配器?android 中怎么自定义个适配器,适配器的数据源是list列表,但我还想要按照需

android 中怎么自定义个适配器?
android 中怎么自定义个适配器,适配器的数据源是list列表,但我还想要按照需求比list列表的数据多一条,就好比腾讯在手机上查看好友状态,多了一项查看更多一条数据?

[解决办法]
一般自定义适配器是继承BaseAdapter,然后重写getView方法,在此方法中你所设计的Item样式填充内容。同时还要注意的是getView方法是通过getCount方法返回的数值来决定调用多少次的。

Java code
public View getView(int position, View convertView, ViewGroup parent) {        ImageView imageView = new ImageView(mContext);        if (convertView == null) {            convertView = inflater.inflate(R.layout.grid_item, null);            imageView = (ImageView) convertView.findViewById(R.id.item_image);            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);            convertView.setTag(imageView);        } else {            imageView = (ImageView) convertView.getTag();        }        imageView.setImageDrawable(drawableList.get(position));        return convertView;    } 

热点排行