Calendar View widget is API level 11 added.It is use to display show calendar to to selection date.It can display Dates.Month And Year.It is customization to change month,day and year and selection to date.
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <CalendarView android:id="@+id/calendar_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java
package com.example.bhaumik.calendarviewdemo; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.CalendarView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { CalendarView calendarView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); calendarView = findViewById(R.id.calendar_view); calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { @Override public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int day) { Toast.makeText(MainActivity.this, day +"-"+month+"-"+year, Toast.LENGTH_SHORT).show(); } }); } }
0 comments:
Post a Comment