在android中写了一个menu,但是点击之后没有反应,求教了!
menu部分代码如下:protectedstaticfinalintMENU_COMMENT=Menu.FIRST;protectedstaticfinalintMENU...
menu部分代码如下:
protected static final int MENU_COMMENT = Menu.FIRST;
protected static final int MENU_COLLECTION = Menu.FIRST+1;
protected static final int MENU_SEARCH= Menu.FIRST+2;
protected static final int MENU_ABOUT = Menu.FIRST+3;
protected static final int MENU_QUIT= Menu.FIRST+4;
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(2,MENU_COMMENT,0,"书评");
menu.add(2,MENU_COLLECTION,0,"我读");
menu.add(2,MENU_SEARCH,0,"搜书");
menu.add(2,MENU_ABOUT,0,"关于");
menu.add(2,MENU_QUIT,0,"退出");
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemMenu(MenuItem item){
//super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case MENU_COMMENT:
actionClickMenuItem1();
case MENU_COLLECTION:
actionClickMenuItem2();
case MENU_SEARCH:
actionClickMenuItem3();
case MENU_ABOUT:
openOptionsDialog();
break;
case MENU_QUIT:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
private void actionClickMenuItem3(){
// TODO Auto-generated method stub
setTitle("搜书");
//Intent intent1 = new Intent(ActivityMain.this, ActivitySearch.class);
//startActivity(intent1);
Intent intent = new Intent();
intent.setClass(ActivityMain.this, ActivitySearch.class);
startActivity(intent);
}
private void actionClickMenuItem2() {
// TODO Auto-generated method stub
setTitle("我读");
Intent intent1 = new Intent(ActivityMain.this, ActivityCollection.class);
startActivity(intent1);
}
private void actionClickMenuItem1() {
// TODO Auto-generated method stub
setTitle("书评");
Intent intent1 = new Intent(ActivityMain.this, ActivityCommentList.class);
startActivity(intent1);
}
private void openOptionsDialog() {
// TODO Auto-generated method stub
new AlertDialog.Builder(this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
} 展开
protected static final int MENU_COMMENT = Menu.FIRST;
protected static final int MENU_COLLECTION = Menu.FIRST+1;
protected static final int MENU_SEARCH= Menu.FIRST+2;
protected static final int MENU_ABOUT = Menu.FIRST+3;
protected static final int MENU_QUIT= Menu.FIRST+4;
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(2,MENU_COMMENT,0,"书评");
menu.add(2,MENU_COLLECTION,0,"我读");
menu.add(2,MENU_SEARCH,0,"搜书");
menu.add(2,MENU_ABOUT,0,"关于");
menu.add(2,MENU_QUIT,0,"退出");
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemMenu(MenuItem item){
//super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case MENU_COMMENT:
actionClickMenuItem1();
case MENU_COLLECTION:
actionClickMenuItem2();
case MENU_SEARCH:
actionClickMenuItem3();
case MENU_ABOUT:
openOptionsDialog();
break;
case MENU_QUIT:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
private void actionClickMenuItem3(){
// TODO Auto-generated method stub
setTitle("搜书");
//Intent intent1 = new Intent(ActivityMain.this, ActivitySearch.class);
//startActivity(intent1);
Intent intent = new Intent();
intent.setClass(ActivityMain.this, ActivitySearch.class);
startActivity(intent);
}
private void actionClickMenuItem2() {
// TODO Auto-generated method stub
setTitle("我读");
Intent intent1 = new Intent(ActivityMain.this, ActivityCollection.class);
startActivity(intent1);
}
private void actionClickMenuItem1() {
// TODO Auto-generated method stub
setTitle("书评");
Intent intent1 = new Intent(ActivityMain.this, ActivityCommentList.class);
startActivity(intent1);
}
private void openOptionsDialog() {
// TODO Auto-generated method stub
new AlertDialog.Builder(this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
} 展开
3个回答
展开全部
onOptionsItemMenu这个函数里面的case语句有错,下面是我下的一段代码,你看一下,应该知道你那个是什么错误了。
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case 1:
sign = 1;
provinces=new String[]{"工具","关于","退出"};
showSingleChoiceDialog();
return true ;
case 2:
sign = 2;
provincesstep=new String[]{"选择提示音","退出"};
showSingleChoiceDialogStep();
return true;
case 3:
notificationManager.cancel(R.drawable.icon);
System.exit(0);
return true;
}
return false;
}
注意里面的return语句。
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case 1:
sign = 1;
provinces=new String[]{"工具","关于","退出"};
showSingleChoiceDialog();
return true ;
case 2:
sign = 2;
provincesstep=new String[]{"选择提示音","退出"};
showSingleChoiceDialogStep();
return true;
case 3:
notificationManager.cancel(R.drawable.icon);
System.exit(0);
return true;
}
return false;
}
注意里面的return语句。
展开全部
public boolean onOptionsItemMenu(MenuItem item){
错了 你加个 @Override 就看到了
用public boolean onOptionsItemSelected(MenuItem item 就可以了
错了 你加个 @Override 就看到了
用public boolean onOptionsItemSelected(MenuItem item 就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
menu.add(2,MENU_COMMENT,MENU_COMMENT,"书评");
其他修改类似
其他修改类似
更多追问追答
追问
请问下 menu.add()第三项参数不是顺序吗?
追答
嗯,排序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询