继续获得无法解析符号' logout'错误
在开关语句中关键字登录时,请继续出现错误,因为无法解决符号注销。 想要将图标放在动作栏上,但不知道如何设置动作栏。请帮助我设置Action Bar也可以解决此问题。 谢谢
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//handle presses on the action bar items
switch (item.getItemId())
{
case R.id.logout:
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setMessage("Do you want to logout?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(Attendence.this,ChoosePanel.class));
} //public void onClick(DialogInterface dialog, int id)
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//action for 'NO' button
dialog.cancel();
} //public void onClick(DialogInterface dialog, int id)
});
//creatin dialog box
AlertDialog alert=builder.create();
//setting the title manually
alert.setTitle("LOGOUT");
alert.show();
return true;
}
Keep getting error with keyword logout in switch statement as as cannot resolve symbol logout.
want to put icon on action bar but don't know how to setup action bar. help me setup action bar resolve this issue as well please.
thanks
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//handle presses on the action bar items
switch (item.getItemId())
{
case R.id.logout:
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setMessage("Do you want to logout?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(Attendence.this,ChoosePanel.class));
} //public void onClick(DialogInterface dialog, int id)
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//action for 'NO' button
dialog.cancel();
} //public void onClick(DialogInterface dialog, int id)
});
//creatin dialog box
AlertDialog alert=builder.create();
//setting the title manually
alert.setTitle("LOGOUT");
alert.show();
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要创建一个操作栏,您必须创建资源类型“菜单”的资源文件。
在该文件中,您可以根据需要拥有尽可能多的选项,并且可以将其定义在栏上或OU上“三个获得”菜单。这是一个示例:
注意
android:id
定义中的 @+id。还请注意,如果您添加App:showasaction =“ ifroom”
该选项将显示在栏上而不是下拉菜单上。然后,在您的活动中,添加
onCreateOptionsMenu(菜单菜单)
方法。类似:然后,您在问题中显示的功能将捕获菜单点击事件。
To create an action bar you have to create a resource file of resource type "Menu".
In that file you can have as much options as you want and can define them to be shown on the bar or ou the "three got" menu. Here is an example:
Note the @+id in the
android:id
definition. Note as well that if you addapp:showAsAction="ifRoom"
the option will be shown on the bar instead of the dropdown menu.Then, in your activity, add the
onCreateOptionsMenu(Menu menu)
method. Something like:Then the function that you showed in your question will catch the menu click events.