Java ';'预期误差

Java ';' expected error

我为一些代码苦苦挣扎了几天。多次尝试,请参阅我的其他问题。现在他们期待一个“;”但我不知道为什么。

holder.valueLabel.setOnClickListener(view -> {
            if (item.value.equals(""))
                try {
                    String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
                    holder.valueLabel.setText(date);
                    mItems.get(position).value = date;
                    showDatePickerDialog(holder.valueLabel.getText().toString(), (datePicker, year, month, day) -> {
                        String dateInFormat = getDateInFormat(year, month, day);
                        holder.valueLabel.setText(dateInFormat);
                        mItems.get(position).value = dateInFormat;

                        (DialogInterface.BUTTON_NEGATIVE), "cancel", (DialogInterface.OnClickListener) (dialog, which) -> {
                            if (which == DialogInterface.BUTTON_NEGATIVE) {
                                mItems.get(position).value = "";
                            } else {
                                mItems.get(position).value = dateInFormat;
                            }
                            ----->}); <--------------

                    }).show();
                } catch (ParseException e) {
                    e.printStackTrace();
                }

            else {
                try {
                    showDatePickerDialog(holder.valueLabel.getText().toString(), (datePicker, year, month, day) -> {
                        String dateInFormat = getDateInFormat(year, month, day);
                        holder.valueLabel.setText(dateInFormat);
                        mItems.get(position).value = dateInFormat;
                    }).show();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
});

显示日期选择器对话框

private DatePickerDialog showDatePickerDialog(String date, DatePickerDialog.OnDateSetListener listener) throws ParseException {
    Calendar myCalendar = getDateFromFormat(date);
    return new DatePickerDialog(getContext(), R.style.AppTheme_DialogTheme, listener,
            myCalendar.get(Calendar.YEAR),
            myCalendar.get(Calendar.MONTH),
            myCalendar.get(Calendar.DAY_OF_MONTH)
    );

}

您没有正确实现 DatePickerDialog 方法尝试以下方式解决您得到的错误:

holder.valueLabel.setOnClickListener(view -> {
            if (item.value.equals(""))
                try {
                    String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
                    holder.valueLabel.setText(date);
                    mItems.get(position).value = date;
                    DatePickerDialog datePickerDialog = showDatePickerDialog(holder.valueLabel.getText().toString(), new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            String dateInFormat = getDateInFormat(year, month, day);
                            holder.valueLabel.setText(dateInFormat);
                            mItems.get(position).value = dateInFormat;
                        }

                    });
                    datePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "cancel", (dialog, which) -> {
                        holder.valueLabel.setText("");
                        mItems.get(position).value = "";
                    });
                    datePickerDialog.show();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            else {
                try {
                    showDatePickerDialog(holder.valueLabel.getText().toString(), (datePicker, year, month, day) -> {
                        String dateInFormat = getDateInFormat(year, month, day);
                        holder.valueLabel.setText(dateInFormat);
                        mItems.get(position).value = dateInFormat;
                    }).show();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });