我想對我的活動使用CalenderView
,我也嘗試清理我的項目,但這個問題沒有解決。如何使用CalendarView投射LinearLayout?
這是我的代碼:
Cal_view.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CalendarView
android:layout_width="match_parent"
android:layout_height="264dp" />
</LinearLayout>
的main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.malik.auealert.HistoryActivity">
<include
android:id="@+id/calendarView"
layout="@layout/cal_view" />
</RelativeLayout>
ActivityClass:
public CalendarView c;
// public TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
// LinearLayout parent = (LinearLayout) View v;
/* ***ERROR Appear on here***: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.CalendarView */
c = (CalendarView) findViewById(R.id.calendarView);
//t = (TextView) findViewById(R.id.message);
c.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
}
});
我搜索谷歌的解決方案,但找不到一個。
'R.id.calendarView'不是您的calendarview的正確ID,事實上您的calendarview甚至沒有ID – tyczj
如果您包含'LinearLayout',然後爲其分配id'calendarView',然後查看查看並將其轉換爲'CalendarView',當錯誤顯示「無法投射到CalendarView」時,您認爲是什麼問題? –
@DavidMedenjak感謝您的回覆我想知道如何解決這個問題? – Omore