<bdo id='cKjAk'></bdo><ul id='cKjAk'></ul>
        <tfoot id='cKjAk'></tfoot>

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

        <small id='cKjAk'></small><noframes id='cKjAk'>

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

        如何从 Android 中的对话框启动 Activity

        时间:2023-08-30
        <tfoot id='u83Vx'></tfoot>

        <small id='u83Vx'></small><noframes id='u83Vx'>

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

            <tbody id='u83Vx'></tbody>
          • <bdo id='u83Vx'></bdo><ul id='u83Vx'></ul>
              1. <legend id='u83Vx'><style id='u83Vx'><dir id='u83Vx'><q id='u83Vx'></q></dir></style></legend>

                  本文介绍了如何从 Android 中的对话框启动 Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我创建了一个自定义对话框,我想在单击确定"时开始一个新活动.如何获取上下文以将其设置为 Intent 构造函数的第一个参数?

                  I created a custom dialog and I'd like to start a new activity when OK is clicked. How can I get the context to set it as first argument of my Intent constructor?

                  我可以使用 getContext() 创建意图,但我不能调用 startActivity.我应该将调用对话框的活动传递给对话框的构造函数吗?是否是通过单击对话框来启动活动的常用方式?

                  I can create the intent using getContext(), but I can't call startActivity. Shall I pass the activity calling the dialog to the dialog's constructor? Is it the usual way to start an activity by clicking a dialog?

                  public class CustomDialog extends Dialog implements OnClickListener {
                      Button okButton, cancelButton;
                  
                      public CustomDialog(Context context) {      
                          super(context);     
                          setContentView(R.layout.custom_dialog);
                          okButton = (Button) findViewById(R.id.button_ok);
                          okButton.setOnClickListener(this);
                          cancelButton = (Button) findViewById(R.id.button_cancel);
                          cancelButton.setOnClickListener(this);
                      }
                  
                      @Override
                      public void onClick(View v) {       
                          if (v == cancelButton)
                              dismiss();
                          else {
                              Intent i = new Intent(getContext(), ItemSelection.class);
                              startActivity(i); //The method startActivity(Intent) is undefined for the type CustomDialog
                          }
                      }
                  }
                  

                  推荐答案

                  public class CustomDialog extends Dialog implements OnClickListener {
                    Button okButton, cancelButton;
                    Activity mActivity;
                  
                    public CustomDialog(Activity activity) {      
                      super(activity);
                      mActivity = activity;
                      setContentView(R.layout.custom_dialog);
                      okButton = (Button) findViewById(R.id.button_ok);
                      okButton.setOnClickListener(this);
                      cancelButton = (Button) findViewById(R.id.button_cancel);
                      cancelButton.setOnClickListener(this);
                    }
                  
                    @Override
                    public void onClick(View v) {       
                      if (v == cancelButton)
                          dismiss();
                      else {
                          Intent i = new Intent(mActivity, ItemSelection.class);
                          mActivity.startActivity(i);
                      }
                    }
                  }
                  

                  这篇关于如何从 Android 中的对话框启动 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:对话框内选项卡布局内的Android listview无法显示滚 下一篇:为每个对话框更改对话框主题

                  相关文章

                  最新文章

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

                  <small id='euIpB'></small><noframes id='euIpB'>

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