如何从单个菜单选项开始新活动
您好,我正在尝试使用单个菜单选项(R.id.waypointEditId)打开一个新活动(GPSWptsEdit.class),但我对代码没有太多运气。每次我在 Eclipse 中以调试模式运行 GPSTrialActivity 并单击菜单选项时,当我单击“是”时,eclispe 中会弹出一个名为“确认透视切换”的窗口,默认检测选项卡显示“未找到源 - JAR 文件 C” :\Program Files (x86)\Android\android-sdk\platfoms\android-8\android.jar 没有附加源
如果有人可以提供一些建议,我们将不胜感激。是我一直在玩的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.waypointEditId:
waypointEdit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void waypointEdit(){
startActivity(new Intent(GPSTrialActivity.this, GPSWptsEdit.class));
}
}
Hi i am trying to open a new activity (GPSWptsEdit.class) with a single menu option (R.id.waypointEditId) but I am not having much luck with the code. Each time I run the GPSTrialActivity in debug mode in eclipse and click on the menu option I get a window pop up in eclispe called "Confirm Perspective Switch" when I click yes, the defualt instrumentation tab says "Source not found - The JAR file C:\Program Files (x86)\Android\android-sdk\platfoms\android-8\android.jar has no source attached.
If someone could assist with some suggestions, it would be much apreciated. Here is the code I have been playing with:
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.waypointEditId:
waypointEdit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void waypointEdit(){
startActivity(new Intent(GPSTrialActivity.this, GPSWptsEdit.class));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在我的项目中使用了同样的东西并且效果很好。
我用过:
你遇到了什么问题?
i have used the same thing in my project and it was working well.
i used:
What problem do you get?
在menifest中添加活动GPSWptsEdit。
add Activity GPSWptsEdit in menifest .
问题可能是您在 switch-case 构造中缺少
break
;尝试使用这段代码但是你能说出问题是什么吗?您遇到哪些错误? logcat 说什么?
The problem might be that you're missing the
break
in your switch-case construction; try with this codeBut could you tell what is the problem? Which errors you get? What does the logcat say?
在阅读了提供的评论后,我最终解决了这个问题。
结果我忘记修改了:
I did end up resolving the issue, after reading the comments provided.
Turns out that, I forgot to amend this: