Function to Open Calendarview by clicking the RelayoutLayout

0

I have a screen where I would like the user to click and open the system's native calendar. But I would like the CalendarView to be opened even if I clicked on the RelativeLayout that covers it. I already gave an ID for RelativeLayout , but how do I open CalendarView .

Javacodetogetthedate:

@OverridepublicvoidonSelectedDayChange(CalendarViewcalendarView,intyears,intmonth,intdayOfMonth){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>

    
asked by anonymous 04.07.2016 / 13:17

1 answer

1

To intercept the "click" in RelativeLayout add a OnClickListener() to it:

layout = (RelativeLayout) findViewById(R.id.calendar);
layout.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(MainActivity.this, "Layout clicked", Toast.LENGTH_SHORT).show();
        chamarCalendar();
    }
});

If you want to click on the EditeText call the calendar instead of the keyboard add this:

editText = (EditText) findViewById(R.id.editText4);
editText.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Toast.makeText(MainActivity.this, "EditText clicked", Toast.LENGTH_SHORT).show();
        chamarCalendar();
        return true;
    }
});

The code should be placed in the% method of Activity

    
04.07.2016 / 17:43