0
I have a screen where I would like the user to click and open the system’s native calendar. Only I would like the CalendarView
was opened even if you clicked on RelativeLayout
that covers it. I already gave an ID to the RelativeLayout
, but as I open the CalendarView
.
Java code to get the date:
@Override
public void onSelectedDayChange(CalendarView calendarView, int years, int month, int dayOfMonth) {
Toast.makeText(getApplicationContext(),dayOfMonth + "/" + month + "/" + years, Toast.LENGTH_LONG).show();
}
});
XML code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/card_view_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="5dp">
<RelativeLayout
android:id="@+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:text="@string/datapgto"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText4"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:inputType="date" />
</RelativeLayout>
</android.support.v7.widget.CardView>
This date is to be given only through the calendar or can be given by the keyboard?
– ramaral
Through the calendar only. When I click open the calendar, then select the date and it inserts into the field the date I chose.
– Artur Mafezzoli Júnior
@Bruno. I have doubts that his edition translates what the AP wants to ask. In the original nothing indicates that he can not open the Calendar.
– ramaral
@ramaral, good that Bruno edited. Because that was my same question. Maybe I didn’t know how to express myself.
– Artur Mafezzoli Júnior
I could have said it in my answer. I got the idea that she had answered the question. Do you have the code for the method
chamarCalendar()
? Where is this Calendarview?– ramaral
@ramaral I don’t have the method yet. I was looking here on the internet some tutorials and saw the same code I posted up there. In the tutorial only had this. And his worked properly, the only difference is that he had a button on the screen to call the calendar. In my case I have a whole Relativelayout.
– Artur Mafezzoli Júnior
I can’t be sure but in principle the code that should put in the method
chamarCalendar
will be the one in the onClickListener from the button you spoke of.– ramaral
I will contact the tutorial owner to better understand what he did there. As I said before, the same code I posted there he did. Thanks for your help, fellas.
– Artur Mafezzoli Júnior