I'm working on a Calendar and I am using a GridLayout for it, now I want to add events. My event is a cell in a specific position (row, column) and maybe the event it would take 2 rows (events longer than 1 hour). I did an example in xml, but I don't know how to add my events dynamically.
My XML:
<GridLayout
android:id="@+id/gridBodyCalendar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="8"
android:rowCount="24"
android:background="@color/blanco">
<!-- Cells without Events-->
.
.
.
<LinearLayout
style="@style/WeeklyHourCell"
android:layout_columnWeight="1"
android:layout_column="4"
android:layout_row="4">
<Space
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
.
.
.
<!-- After I create all cells, for ui testing I added my event cells in a specific row/columns; it seems to replace or overlap the previous cell of the x,y position -->
<!-- Wednesday from 16:00 to 17:30-->
<!-- RowSpan 2 because it takes longer than 1 hour -->
<LinearLayout
style="@style/WeeklyHourCell"
android:layout_row="16"
android:layout_column="3"
android:layout_rowSpan="2"
android:orientation="vertical"
>
<!-- Space; is the event doesn't start exactly at 16:00 it would need a weight != from 0-->
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0" />
<!-- The event with styles and specific properties -->
<LinearLayout
android:id="@+id/linReunionInternaEjemplo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="@color/fondo_reunion_interna_calendario"
android:layout_weight="0.75"
>
<LinearLayout
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="@color/color_reunion_interna_calendario"
></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:text="Jhon Smith"
android:textColor="@color/color_reunion_interna_calendario"
android:maxLines="1"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:textColor="@color/color_reunion_interna_calendario"
android:maxLines="1"
android:text="San Borja"/>
</LinearLayout>
</LinearLayout>
<!-- End Event -->
<!-- Space for the event that doesn't finish exactly at 18:00-->
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
/>
</LinearLayout>
.
.
.
</GridLayout>
The xml draw a event like I wish, but I need to load multiple events from my database so I can't create my events in my xml. I need to create my events programatically, set its properties and add it in a specific row/column. How can I start to do that?