如何在onDateSet中使用switch case

时间:2017-04-27 08:53:44

标签: android

我将使用多个日期选择器如何在OnDateSet中使用switch case。

labelSelectedDate =(TextView)toolbar.findViewById(R.id.textview_label_selected_date); //从日期开始

        labelSelectedDateTo= (TextView) toolbar.findViewById(R.id.textview_label_selected_date_todate); //To date

        selectedDate = (TextView) toolbar.findViewById(R.id.textview_selected_date);  //From date

        selectedDateTo= (TextView) toolbar.findViewById(R.id.textview_selected_date_todate); //To date

        datePicker = (ImageView) toolbar.findViewById(R.id.imageview_date_picker); //From date

        datePickerTo= (ImageView) toolbar.findViewById(R.id.imageview_date_picker_todate);//To date

public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth){

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, monthOfYear, dayOfMonth);
    Date date = calendar.getTime();

    switch () {

        case :

            selectedDateForSalesVsTarget = CashPunditUtils.formatDate(date, "MM-dd-yyyy");

            Log.d(TAG, "Date Set : " + selectedDateForSalesVsTarget);

            if (selectedDate != null) {

                selectedDate.setText(CashPunditUtils.formatDate(date, "dd MMM yy"));

            }
            CashPunditUtils.viewId++;
            break;
        case :

            selectedDateForSalesVsTargetTo = CashPunditUtils.formatDate(date, "MM-dd-yyyy");

            Log.d(TAG, "Date Set : " + selectedDateForSalesVsTarget);

            if (selectedDateTo != null) {

                selectedDateTo.setText(CashPunditUtils.formatDate(date, "dd MMM yy"));
            }

            break;
    }
    loadSummaryReports(SALES_VS_TARGET_REPORT, false);
}

1 个答案:

答案 0 :(得分:0)

在switch中传递view.getId()并在不同情况下使用不同的R.id.datapickerid