我一直在浏览过去4个小时,发现我必须在我的xml中创建一个calendarview并在我的java文件中实例化它。但我真的无法理解如何在屏幕上显示实际日历本身。
我的xml文件
<CalendarView
android:id="@+id/calen"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
java文件
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”..
任何帮助,提示和指导都将不胜感激。
答案 0 :(得分:0)
我认为这就像改变一样简单:
calender = (Calendar)findViewById(R.id.calen);
为:
CalendarView calender = (CalendarView) findViewById(R.id.calen);
答案 1 :(得分: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);
}
}
答案 2 :(得分: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));
}
}