• <small id='cVjoW'></small><noframes id='cVjoW'>

    1. <tfoot id='cVjoW'></tfoot>
      <legend id='cVjoW'><style id='cVjoW'><dir id='cVjoW'><q id='cVjoW'></q></dir></style></legend>

        • <bdo id='cVjoW'></bdo><ul id='cVjoW'></ul>
        <i id='cVjoW'><tr id='cVjoW'><dt id='cVjoW'><q id='cVjoW'><span id='cVjoW'><b id='cVjoW'><form id='cVjoW'><ins id='cVjoW'></ins><ul id='cVjoW'></ul><sub id='cVjoW'></sub></form><legend id='cVjoW'></legend><bdo id='cVjoW'><pre id='cVjoW'><center id='cVjoW'></center></pre></bdo></b><th id='cVjoW'></th></span></q></dt></tr></i><div id='cVjoW'><tfoot id='cVjoW'></tfoot><dl id='cVjoW'><fieldset id='cVjoW'></fieldset></dl></div>

        onOptionsItemSelected android中的警报对话框

        时间:2023-08-30

            <tfoot id='RXC8A'></tfoot>
          • <small id='RXC8A'></small><noframes id='RXC8A'>

                <bdo id='RXC8A'></bdo><ul id='RXC8A'></ul>
                    <tbody id='RXC8A'></tbody>
                  <i id='RXC8A'><tr id='RXC8A'><dt id='RXC8A'><q id='RXC8A'><span id='RXC8A'><b id='RXC8A'><form id='RXC8A'><ins id='RXC8A'></ins><ul id='RXC8A'></ul><sub id='RXC8A'></sub></form><legend id='RXC8A'></legend><bdo id='RXC8A'><pre id='RXC8A'><center id='RXC8A'></center></pre></bdo></b><th id='RXC8A'></th></span></q></dt></tr></i><div id='RXC8A'><tfoot id='RXC8A'></tfoot><dl id='RXC8A'><fieldset id='RXC8A'></fieldset></dl></div>
                  <legend id='RXC8A'><style id='RXC8A'><dir id='RXC8A'><q id='RXC8A'></q></dir></style></legend>
                1. 本文介绍了onOptionsItemSelected android中的警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我的一个 OptionsMenuItems 被点击时,我试图打开一个警告对话框.如果用户单击是"则继续操作,如果单击否"则取消.我只是不知道如何编写代码.这就是我所拥有的:

                  I'm trying to bring up an alert dialog box when one of my OptionsMenuItems is clicked. Proceed with operation if user clicks "yes", cancels if clicks no. I just don't know how to do the code. This is what I have:

                  @Override
                  public boolean onOptionsItemSelected(MenuItem item)
                  { 
                  
                      switch (item.getItemId()) { 
                      case R.id.exit:
                          this.finish();
                          return true;
                      case R.id.about:
                          Intent i = new Intent(this, AboutActivity.class);
                          this.startActivity(i);
                      case R.id.skip:
                          AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
                  
                              // set the message to display
                              alertbox.setMessage("The yoga pose will be skipped from now on!").show();
                             alertbox.setCancelable(true);
                             alertbox.setNegativeButton("no").setPositiveButton("OK", new DialogClicklistener() { 
                  
                               // click listener on the alert box
                              public boolean onClick(DialogInterface arg0, int arg1) {
                                  // the button was clicked
                                  boolean success = myDbHelper.setSkip(PoseID);
                                  SetImageView2(myDbHelper);
                                  return success;
                                }
                  
                             });
                  
                             // add a neutral button to the alert box and assign a click listener
                             alertbox.setCancelable(true).set(onCancelListener) {
                  
                                // click listener on the alert box
                                 public boolean onClick(DialogInterface arg0, int arg1) {
                                  // the button was clicked
                  
                                }
                             });
                             // show it
                             alertbox.show();
                  
                       default: 
                              return super.onOptionsItemSelected(item);
                      }
                  }
                  

                  推荐答案

                  以下内容直接来自我目前正在开发的应用程序.它会弹出一个 AlertDialog,然后将用户带到不同的活动(在他们输入密码之后).如果我能澄清任何事情,请告诉我.

                  The following is directly from the app I'm currently working on. It brings up an AlertDialog which then takes the user to a different activity (after they enter a password). Please let me know if I can clarify anything about it.

                  现在包括整个方法.

                  @Override
                  public boolean onOptionsItemSelected(MenuItem item) { 
                      LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
                      final int menuItem = item.getItemId();
                      if ((menuItem == R.id.survey) || (menuItem == R.id.syncMode)) {
                          View layout = inflater.inflate(R.layout.survey_password_dialog, (ViewGroup) findViewById(R.id.layout_root));
                          final EditText password = (EditText) layout.findViewById(R.id.passwordText);
                          AlertDialog.Builder builder = new AlertDialog.Builder(this);            
                          builder.setView(layout)
                          .setCancelable(false)
                          .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int id) {   
                              }
                          })
                          .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {
                                  dialog.cancel();
                              }
                          });
                          final AlertDialog alertDialog = builder.create();
                          alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
                              @Override
                              public void onShow(DialogInterface dialog) {
                                  Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                                  b.setOnClickListener(new View.OnClickListener() {
                                      @Override
                                      public void onClick(View view) {
                                          if (password.getText().toString().equalsIgnoreCase("the_password")) {
                                              if (menuItem == R.id.survey) {
                                                  Intent intent = new Intent(AsthmaAppActivity.this, SurveyActivity.class);
                                                  startActivity(intent);
                                                  alertDialog.dismiss();
                                              }
                                              else { //(menuItem == R.id.syncMode) 
                                                  startActivity(new Intent(AsthmaAppActivity.this, SyncMode.class));
                                                  alertDialog.dismiss();
                                              }
                                          }
                                          else Toast.makeText(AsthmaAppActivity.this, "Password incorrect", Toast.LENGTH_LONG).show();
                                      }
                                  });
                              }
                          });
                          alertDialog.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                          alertDialog.show();
                      }
                      else {  //dialog for setting application parameters "on the fly" for application testing
                          View layout = inflater.inflate(R.layout.parameter_change, (ViewGroup) findViewById(R.id.layout_root));
                          final EditText parameter = (EditText) layout.findViewById(R.id.parameterText);
                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
                          builder.setView(layout)
                          .setCancelable(false)
                          .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {  
                                  String parameterString = parameter.getText().toString();
                                  if(parameterString == null || parameterString.isEmpty()) {
                                      testParam = 0.0;
                                  } 
                                  else {
                                      testParam = Double.parseDouble(parameterString);
                                  }
                              }
                          })
                          .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {
                                  dialog.cancel();
                              }
                          })
                          .show();
                      }
                      return(super.onOptionsItemSelected(item));
                  } 
                  

                  这篇关于onOptionsItemSelected android中的警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android:旋转更改后对话框等恢复 下一篇:如何将我的应用添加到 Android 的“共享照片&quo

                  相关文章

                  最新文章

                    <legend id='Ts5Da'><style id='Ts5Da'><dir id='Ts5Da'><q id='Ts5Da'></q></dir></style></legend>

                    <i id='Ts5Da'><tr id='Ts5Da'><dt id='Ts5Da'><q id='Ts5Da'><span id='Ts5Da'><b id='Ts5Da'><form id='Ts5Da'><ins id='Ts5Da'></ins><ul id='Ts5Da'></ul><sub id='Ts5Da'></sub></form><legend id='Ts5Da'></legend><bdo id='Ts5Da'><pre id='Ts5Da'><center id='Ts5Da'></center></pre></bdo></b><th id='Ts5Da'></th></span></q></dt></tr></i><div id='Ts5Da'><tfoot id='Ts5Da'></tfoot><dl id='Ts5Da'><fieldset id='Ts5Da'></fieldset></dl></div>

                    1. <tfoot id='Ts5Da'></tfoot>
                        <bdo id='Ts5Da'></bdo><ul id='Ts5Da'></ul>
                    2. <small id='Ts5Da'></small><noframes id='Ts5Da'>