问题

@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;
}
}
Here I am temporarily trying to add text view dynamically but I want to inflate here my custom activity_item layout and add it to grid cell.
回答1:
do you mean that you wish to add multiple rows in the area that is now being taken by the "Busy" space ? do you want it to take as much space as it needs, or should it be scrollable?
anyway, it seems you are in the right direction. you used a linearLayout to hold the "busy" area, right? so just use a for-loop and put their the data you wish to show.
of course, because the gridView recycles items, you would need to empty the linearLayout every time you reach the getView, but it should still work.
if you wish to use the layoutInflater in the for-loop, that's also possible:
subRow = inflater.inflate(R.layout.sub_row, linearLayout, true);
来源:https://stackoverflow.com/questions/17629542/how-to-inflate-another-layout-inside-getview-of-gridview-adapter-in-android