0

我过去 4 小时一直在浏览,发现我必须在我的 xml 中创建一个 calendarview 并在我的 java 文件中实例化它。但我真的无法理解如何在屏幕上显示实际的日历本身。

我的xml文件

  <CalendarView
        android:id="@+id/calen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

文件

 package org.example.calender;

import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;

public class CalenderActivity extends Activity {
    Calendar calender;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        calender = (Calendar)findViewById(R.id.calen);
    }
}

此外,它在“CALEN”上给出错误,但是我的日历视图 ID 也是“CALEN”。

任何帮助、提示和指导将不胜感激。

4

3 回答 3

0

我认为这就像改变一样简单:

calender = (Calendar)findViewById(R.id.calen);

到:

CalendarView calender = (CalendarView) findViewById(R.id.calen);
于 2012-04-22T15:59:35.903 回答
0
 package org.example.calender;

import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;

public class CalenderActivity extends Activity {
    CalendarView calender;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        calender = (CalendarView)findViewById(R.id.calen);
    }
}
于 2012-04-22T16:08:23.827 回答
0

只需尝试此代码:::

package org.example.calender;

import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;

public class CalenderActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new CalenderView(this));
    }
}
于 2012-04-22T16:09:51.987 回答