【问题标题】:I want to show the results of the spin in a popup instead of toast我想在弹出窗口而不是 toast 中显示旋转的结果
【发布时间】:2020-04-02 00:22:48
【问题描述】:

我的代码“纺车”有一点问题,我想在弹出窗口中显示结果,而不是在 toast 文本中显示 这是代码的主要活动

        @Override
        public void onClick(View view) {
            int index = getRandomIndex();
            luckyWheelView.startLuckyWheelWithTargetIndex(index);
        }
    });

    luckyWheelView.setLuckyRoundItemSelectedListener(new LuckyWheelView.LuckyRoundItemSelectedListener() {
        @Override
        public void LuckyRoundItemSelected(int index) {
            Toast.makeText(getApplicationContext(), data.get(index).topText, Toast.LENGTH_SHORT).show();
        }
    });
}

private int getRandomIndex() {
    Random rand = new Random();
    return rand.nextInt(data.size() - 1) + 0;
}

private int getRandomRound() {
    Random rand = new Random();
    return rand.nextInt(10) + 15;
}

【问题讨论】:

    标签: java android android-studio mobile


    【解决方案1】:

    我认为您正在寻找Dialog 的某个版本。你可能想要一个AlertDialog

    android 文档很好地概述了这些:

    https://developer.android.com/guide/topics/ui/dialogs#AlertDialog

    AlertDialog 类允许您构建各种对话框设计,并且通常是您需要的唯一对话框类。”

    【讨论】:

      【解决方案2】:

      首先在您的活动中添加此方法:

         public void startAlert(String title , String message){
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle(title);
      builder.setMessage(message);
      builder.setCancelable(true);
      builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // here you can do anything you want
          }
      });
      builder.show();
      }
      

      然后在你的代码中调用它

      【讨论】:

        猜你喜欢
        • 2016-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多