2016-02-03 74 views
0

我試圖使一個烹飪應用一頓飯規劃師我做日曆視圖的Android 2

我有以下代碼

calendar_view.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" > 


<TextView 
    android:id="@+id/textView1" 
    android:textColor="#FF0000" 
    android:textSize="20dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="30dp" 
    android:text="Static CalendarView" /> 

<CalendarView 
    android:id="@+id/calendarView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/textView1" 
    android:layout_marginTop="60dp" /> 


</RelativeLayout> 

Calendar_View.java

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.CalendarView; 
import android.widget.CalendarView.OnDateChangeListener; 
import android.widget.Toast; 

public class Calendar_View extends Activity { 

CalendarView cal; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.calendar_view); 

    cal = (CalendarView) findViewById(R.id.calendarView1); 

    cal.setOnDateChangeListener(new OnDateChangeListener() { 

     @Override 
     public void onSelectedDayChange(CalendarView view, int year, int month, 
             int dayOfMonth) { 
      // TODO Auto-generated method stub 

      Toast.makeText(getBaseContext(),"Selected Date is\n\n" 
          +dayOfMonth+" : "+month+" : "+year , 
        Toast.LENGTH_LONG).show(); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.calendar_view, menu); 
    return true; 
} 
} 

我收到以下錯誤消息

"Error:(37, 36) error: cannot find symbol variable menu"

我看了看周圍的互聯網上,但無法找到一個類似的問題,我知道我失去了一些東西,但不知道是什麼

有誰知道我缺少或如何解決問題

在此先感謝

回答

0

calendar_view是一個佈局,而不是一個菜單,讓R.menu.calendar_view也就不存在了。 R.layout.calendar_view會存在,但是不能用MenuInflater來誇大 - 您已在onCreate()中正確執行此操作。您可能需要創建一個菜單xml,或者刪除onCreateOptionsMenu()調用。