我正在使用日历,我正在使用GridLayout,现在我想添加事件。我的事件是特定位置(行,列)中的单元格,也可能是需要2行(事件超过1小时)的事件。我在xml中做了一个例子,但我不知道如何动态添加我的事件。
我的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>
xml绘制一个我想要的事件,但我需要从我的数据库加载多个事件,所以我无法在我的xml中创建我的事件。我需要以编程方式创建我的事件,设置其属性并将其添加到特定的行/列中。我该如何开始这样做?