Home>

I am currently creating a calendar app.
I am trying to process the button that appears when I tap the date,
The button is out before tapping the date.
How can I do this?
I tried with a conditional branch, but the result was not what I expected.
The position of the button is appropriate. At the moment, I'm devoted to tapping the date to show the button.
It is part of the current code. For the time being, there may be a cause in the XML file, so I will post it.

 DatePicker datePicker1 = findViewById (R.id.datePicker1);
        datePicker1.init (year, month, day, new DatePicker.OnDateChangedListener () {
            @Override
            public void onDateChanged (DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                // The part that is executed when the date is selected
                Button button = findViewById (R.id.button);
            }
        });
<DatePicker
        android: id = "@ + id/datePicker1"
        android: layout_width = "wrap_content"
        android: layout_height = "744dp"
        android: layout_gravity = "center | top" />
    <Button
        android: id = "@ + id/button"
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: layout_gravity = "center | top"
        android: text = "Button" />
  • Answer # 1

    Isn't it possible to achieve this by switching the display/non-display of buttons?
    * Since the operation has not been confirmed, please make fine adjustments if it does not move.

    ·procedure
    1. Add button hidden setting to XML file
    2. Add processing to Java file to display the button when the date button is pressed
    (If necessary, add some process to hide the button again)

    <Button
        android: id = "@ + id/button"
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: layout_gravity = "center | top"
        android: text = "Button"
        android: visibility = "invisible" /><!-Hide it with "invisible"->
    Button button = findViewById (R.id.button);
    DatePicker datePicker1 = findViewById (R.id.datePicker1);
            datePicker1.init (year, month, day, new DatePicker.OnDateChangedListener () {
                @Override
                public void onDateChanged (DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    // The part that is executed when the date is selected
                    button.setVisibility (View.VISIBLE);// change from hidden state to visible state
                }
            });