我想创建每周日历视图,并且在每个网格项目(每天)内可能有几个活动。除此之外,我使用网格视图创建了每周日历视图,但如果有任何特定日期的活动,我想通过动态添加活动检查分贝。和图片一样。下面是我的 getView() 代码..
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.calendar_week_gridcell, parent, false);
}
txtRowTitle = (TextView) row.findViewById(R.id.txtDayTitle);
LinearLayout root = (LinearLayout) row.findViewById(R.id.linear_root);
String dayTitle = list.get(position);
txtRowTitle.setText(dayTitle);
if (position == currentWeekDay - 1)
root.setBackgroundResource(R.drawable.calheader);
if (!activityMap.isEmpty() && activityMap.containsKey(activityDateList.get(position))) {
TextView item = new TextView(mContext);
item.setText(activityMap.get(activityDateList.get(position)));
item.setBackgroundColor(Color.GREEN);
root.addView(item);
}
return row;
}
}
在这里,我暂时尝试动态添加文本视图,但我想在这里扩展我的自定义 activity_item 布局并将其添加到网格单元格。