Custom adapter in GridView

≡放荡痞女 提交于 2019-12-24 22:16:35

问题


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) ?

(screen for example)


回答1:


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);
     ...
}


来源:https://stackoverflow.com/questions/4875893/custom-adapter-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!