我試圖做出選項菜單,但在switch語句中出現錯誤(所有Case語句中的錯誤無法解決,如R.id.regid
)。Android選項菜單
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId()){
case R.id.regid:Toast.makeText(this,"You pressed the registration menu",Toast.LENGTH_LONG).show();
return true;
case R.id.enqid:Toast.makeText(this,"You pressed the Add Enquiry Menu",Toast.LENGTH_LONG).show();
return true;
case R.id.searchid:Toast.makeText(this,"You pressed the Search Students Menu",Toast.LENGTH_LONG).show();
return true;
case R.id.calid:Toast.makeText(this,"You pressed the calendar Menu for Upcoming batches",Toast.LENGTH_LONG).show();
return true;
case R.id.timingsid:Toast.makeText(this,"You pressed the Batch Timings Menu for Current Batches",Toast.LENGTH_LONG).show();
return true;
case R.id.courseid:Toast.makeText(this,"You pressed jlc Syllabus",Toast.LENGTH_LONG).show();
return true;
case R.id.facultiesid:Toast.makeText(this,"You pressed the faculties details",Toast.LENGTH_LONG).show();
return true;
default:return super.onOptionsItemSelected(item);
}
}
}
Optionmenuitem.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/regid"
android:icon="@drawable/ic_menu_reg"
android:title="@string/reg"
android:alphabeticShortcut="R"
/>
<item
android:id="@+id/enqid"
android:icon="@drawable/ic_enquiry"
android:title="@string/enquiry"
android:alphabeticShortcut="E"
/>
<item
android:id="@+id/searchid"
android:icon="@drawable/searchid"
android:title="@string/search"
android:alphabeticShortcut="S"
/>
<item
android:id="@+id/calid"
android:icon="@drawable/ic_calendar"
android:title="@string/upcomingbatches"
android:alphabeticShortcut="U"
/>
<item
android:alphabeticShortcut="T"
android:id="@+id/timingsid"
android:icon="@drawable/ic_clock"
android:title="timings"
/>
<item
android:id="@+id/courseid"
android:alphabeticShortcut="C"
android:title="JLC Syllabus"
/>
<item
android:id="@+id/facultiesid"
android:title="faculties"
android:icon="@drawable/ic_faculties"
android:alphabeticShortcut="F"
/>
</menu>
下面是在控制檯顯示錯誤消息。
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_menu_reg').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_enquiry').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/searchid').
Error: No resource found that matches the given name (at 'title' with value '@string/search').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_calendar').
Error: No resource found that matches the given name (at Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_faculties').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_menu_reg').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_enquiry').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/searchid').
Error: No resource found that matches the given name (at 'title' with value '@string/search').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_calendar').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_clock').
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_faculties').
該錯誤與您發佈的代碼無關。 – doorstuck