Project XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.demetrius.calendario.MainActivity">
<CalendarView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/calendario">
</CalendarView>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center"
android:onClick="mostrar_data"
android:text="Mostrar data"/>
</LinearLayout>
project java class
public class MainActivity extends AppCompatActivity {
CalendarView calendario;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle(null);
calendario = (CalendarView) findViewById(R.id.calendario);
calendario.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
String date = dayOfMonth + "/" + (month+1) + "/" + year;
Log.d("teste",date);
}
});
}
}