在GridView的自定义适配器 [英] Custom adapter in GridView
本文介绍了在GridView的自定义适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着做一些日历。我这样做是为 GridView控件自定义适配器。
如何在适配器结合2 的TextView (日期和文字)和图标(红圈)?
I try to do some calendar. I do it as GridView with custom adapter. How in adapter combine 2 TextView(date and text) and icons (red circle) ?
推荐答案
您必须创建一个布局(与图标的ImageView的2 TextViews)为每个项目和膨胀的布局成在getView视图()的方法您的适配器。类似
You must create a layout(with an ImageView for the icon and 2 TextViews) for each item and inflate the layout into a view in the getView() method of your adapter. Something like
View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) { // recycled view is null so create it.
convertView = View.inflate(context, R.id.layout, parent);
}
ImageView imageView = convertView.findViewById(R.id.image);
TextView tv1 = convertView.findViewById(R.id.text1);
...
}
这篇关于在GridView的自定义适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文