Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Views (Month, Day, Week) from Android Stock Calendar in a Custom application

In the Google Stock Android Calendar there exists several Views (Month, Week, Agenda, Week), the source code downloaded from Google Android Sources Repositories have the same application, by exploring the code the package named com.android.calendar has the main views responsible for rendering these activities :

enter image description here

with hard working around the code I used two packages com.android.calendar.month and com.android.calendar but couldn't achieve my goal, this is a sample of what I used:

enter image description here

and the following code for the main:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

and here is my xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/month"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:paddingTop="1dip"
    android:background="@null">

    <TextView android:id="@+id/month_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dip"
        android:visibility="gone"
        style="@style/MonthView_MiniMonthLabel" />

    <include android:id="@+id/day_names" layout="@layout/full_month_header" />

     <View
        android:background="@color/calendar_grid_line_inner_vertical_color"
        android:layout_height="1px"
        android:layout_width="match_parent" />

    <com.android.calendar.month.MonthListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawSelectorOnTop="false" />

</LinearLayout>

Till here the code works fine, but the with a blank white screen and an actionbar, if my question was not clear please try to edit it.

What should be done to include Calendar Views (Month, Week, Day) in a custom application ?
like image 912
Mahmoud Hashim Avatar asked Feb 22 '14 08:02

Mahmoud Hashim


1 Answers

You should take a look at CalendarView it is the standard way of integrating calendars in Android.

Also, if you need to select Dates & Time in your UI, there are DatePicker and TimePicker.

Remember that the default calendar app in android is open-source! Feel free to dig through the code here.

like image 113
donfuxx Avatar answered Sep 21 '22 13:09

donfuxx