【问题标题】:Button to start activity if statement用于启动活动的按钮 if 语句
【发布时间】:2012-05-01 07:07:19
【问题描述】:

我希望按钮仅在内容等于 America 时打开对话框。我该怎么做? 我尝试创建一个对话框活动,然后使用一个意图我得到了对话框,但它是单独出现的,而不是当前活动!

if(check.contentEquals("america")){

                           // Then I want the dialog to open here

【问题讨论】:

  • 你已经完成了,在 if 语句中运行你的对话代码 :)

标签: java android button


【解决方案1】:

试试这个:

if(check.contentEquals("america")){
            imageview.setAlpha(0);
            Intent i = new Intent(ACTION NAME);
            startActivity(i);
}

如果你想运行一个简单的对话框,你所要做的就是:

if(check.contentEquals("america")){
            imageview.setAlpha(0);
            mDialog.show();
}

【讨论】:

    【解决方案2】:

    要显示警告对话框试试这个:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setTitle("Title");
    builder.setMessage("your message");
    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override 
    public void onClick(DialogInterface dialog, int which) {
         dialog.dismiss();
      }
    });
    final AlertDialog alert = builder.create();
    
    if(check.contentEquals("america")){
       alert.show();
    }
    

    【讨论】:

    • 我想让已经放在另一个activity中的AlertDialog在当前activity中打开?
    • 不,你可以在当前活动中声明它。如果你能弄清楚,请接受我的回答:)
    • 我正在设计一款游戏。为了保存最后一个活动状态,我添加了一个带有 2 个按钮的菜单 - 保存和加载每个人,当用户单击保存按钮时,我希望保存活动状态,当应用程序再次启动并且用户单击加载按钮时菜单,我想要加载活动状态!是否可以?请务必给出完整代码的示例!
    猜你喜欢
    • 2018-02-15
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多