AndroidStudio error OnClickListener ()

1

I do not know how to fix the error OnClickListener () in the java class below, only has it to fix

Here is the complete code to download: link

Error:

classeOlaCalendario.javapackagecom.example.brainiac.olacalendario;importandroid.annotation.TargetApi;importandroid.app.DatePickerDialog;importandroid.app.Dialog;importandroid.content.DialogInterface;importandroid.content.DialogInterface.OnClickListener;importandroid.icu.util.Calendar;importandroid.os.Build;importandroid.support.annotation.RequiresApi;importandroid.support.v7.app.AppCompatActivity;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;importandroid.widget.DatePicker;importandroid.widget.TextView;publicclassOlaCalendarioActivityextendsAppCompatActivity{privateTextViewmDateDisplay;privateButtonmPickDate;privateintmYear;privateintmMonth;privateintmDay;staticfinalintDATE_DIALOG_ID=0;protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.ola_calendario);mDateDisplay=(TextView)findViewById(R.id.dateDisplay);mPickDate=(Button)findViewById(R.id.pickDate);mPickDate.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv){showDialog(DATE_DIALOG_ID);}});finalCalendarc=Calendar.getInstance();mYear=c.get(Calendar.YEAR);mMonth=c.get(Calendar.MONTH);mDay=c.get(Calendar.DAY_OF_MONTH);updateDisplay();}privatevoidupdateDisplay(){mDateDisplay.setText(newStringBuilder()//Monthis0basedsoadd1.append(mMonth+1).append("-")
             .append(mDay + 1).append("-")
             .append(mYear + 1).append(" "));
}

private DatePickerDialog.OnDateSetListener mDateSetListener=
        new DatePickerDialog.OnDateSetListener(){

            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                mYear = year;
                mMonth = month;
                mDay = dayOfMonth;
                updateDisplay();
            }
        };

@Override
protected Dialog onCreateDialog(int id){
    switch (id){
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this,mDateSetListener, mYear, mMonth, mDay);
    }
    return null;

    }
}

file ola_calendario.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    <TextView
        android:id="@+id/dateDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        />
    <Button
        android:id="@+id/pickDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Altere a Data "
        />
</LinearLayout>'
    
asked by anonymous 03.01.2017 / 01:09

3 answers

0

It seems that this onClickListener is deriving from a class that needs to implement something absent, so just add the View class before the onClickListener to call it from that class, as follows:

    mPickDate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
           showDialog(DATE_DIALOG_ID);
        }
    });

I think it will work.

    
03.01.2017 / 12:38
0

The on-click method needs to be implemented with Override:

@Override
public void onClick(View v) {
    onAcao();
}
    
03.01.2017 / 13:36
-2

Resolved I used Java Calendar instead of Android

import java.util.Calendar;
    
03.01.2017 / 01:47