我尝试创建选项菜单,但是在switch语句中出现错误(所有Case语句中的错误,例如R.id.regid
无法解决)。
@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').
答案 0 :(得分:1)
如果您已导入android.R,请从导入中删除它。如果它仍然不起作用,请尝试清理项目(项目 - &gt;清洁...)
答案 1 :(得分:0)
奥莱特!我猜测控制台中的错误与您的代码无关。
因此,您可以尝试以下步骤:
让我知道它是否适合你。