CalendarView getDate方法返回当前日期,而不是选择日期...我做错了什么?

时间:2017-09-10 18:29:51

标签: android calendarview

我的calendarView无法返回所选日期,而是返回一些始终指向今天的默认值。

我当然正在更改我日历中选择的日期,它确实显示为已更改。我尝试在调试模式下检查视图,但没有找到任何内容。

我在模拟器中运行它,而不是在真正的手机上...我应该修改一些设置吗?我错过了重要的事吗?因为我没有得到所选的日期,而是当前的日期真是令人困惑。

<CalendarView
                            android:id="@+id/view_calendar_create_event_date"
                            android:layout_width="wrap_content"
                            android:layout_height="0dp"
                            android:layout_weight="1" />

这是从事件监听器

调用的
protected void createEvent(View view){
        TextView eventNameView = (TextView) this.findViewById(R.id.createEventNameInput);
        String eventName = eventNameView.getEditableText().toString();

        CalendarView eventOccursOnView = (CalendarView) this.findViewById(R.id.view_calendar_create_event_date);
        long eventOccursOn = eventOccursOnView.getDate();
        Date temporary = new Date(eventOccursOn);

        Event newEvent = new Event(eventName, "", 0, 0, eventOccursOn);
        newEvent.save(view.getContext());
    }

这就是我设置我的事件监听器的方式

saveButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                // Create the event
                EventDetailsActivity.this.createEvent(view);

                // Notify the user
                Snackbar.make(view, "Successfully created a new event!", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                // Return to the previous activity
                finish();
            }
        });

1 个答案:

答案 0 :(得分:1)

您需要实施add_action("admin_init", "download_csv"); function download_csv() { if (isset($_POST['download_csv'])) { function outputCsv( $fileName, $assocDataArray ) { ob_clean(); header( 'Pragma: public' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Cache-Control: private', false ); header( 'Content-Type: text/csv' ); header( 'Content-Disposition: attachment;filename=' . $fileName ); if ( isset( $assocDataArray['0'] ) ) { $fp = fopen( 'php://output', 'w' ); fputcsv( $fp, array_keys( $assocDataArray['0'] ) ); foreach ( $assocDataArray AS $values ) { fputcsv( $fp, $values ); } fclose( $fp ); } ob_flush(); } // This is dummy data. $data = array( array( 'item' => 'Server', 'cost' => 10000, 'approved by' => 'Joe' ), array( 'item' => 'Mt Dew', 'cost' => 1.25, 'approved by' => 'John' ), array( 'item' => 'IntelliJ IDEA', 'cost' => 500, 'approved by' => 'James' ), ); outputCsv( 'expenses.csv', $data ); exit; // This is really important - otherwise it shoves all of your page code into the download } }

setOnDateChangeListener