8

Weekly_Calendar_View I want to create weekly calendar view and inside each grid item (each day) there are may be several activities.Out of this I have created weekly calendar view using grid view but I want to add activities if there are any for particular date by dynamically checking db. Like same as in image. Below is my getView() code..

@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.

Narendra
  • 609
  • 1
  • 12
  • 28
  • I have tried to bind activity items to list view for grid view cell but it's not working properly. I want to inflate here my custom activity_item and it to grid view cell. How I can do it? – Narendra Jul 13 '13 at 11:04
  • @blackbelt can you tell me how can inflate here my custom layout and add it to grid view item for number of activities available on that day. – Narendra Jul 13 '13 at 11:21

1 Answers1

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);
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Actually I want to add that "Busy" like multiple items for number of activities available on that particular day. So how to inflate this custom activity_item layout multiple times and add it to root Linear Layout. – Narendra Jul 13 '13 at 11:45
  • i'm not sure i understand. don't you mean that instead of "busy", you would have a list of items inside? if so, that's the answer i've already written. you also need to decide if it should be scrollable or not, and maybe the maximum number of items to show. it's now a design question. the technical details come after the design... – android developer Jul 13 '13 at 11:52
  • I will try your solution and let you know...thanks for your suggestion. – Narendra Jul 13 '13 at 11:58
  • @Narendra I am working on similar kind of screen can u post some code if u found solution? – Ashok Kateshiya Dec 02 '14 at 04:22