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

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

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

        使用 onDismiss() 从 DialogFragment 获取信息

        时间:2023-08-30

          <tbody id='HkPcA'></tbody>
        <legend id='HkPcA'><style id='HkPcA'><dir id='HkPcA'><q id='HkPcA'></q></dir></style></legend>
        1. <small id='HkPcA'></small><noframes id='HkPcA'>

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

                <tfoot id='HkPcA'></tfoot>

                  本文介绍了使用 onDismiss() 从 DialogFragment 获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个应用程序,并且正在使用扩展 DialogFragment 的自定义对话框.此对话框将包含我想传递给父活动的某些字段.我尝试实现 OnDismissListener 但参数是对话框接口.

                  I am working on an app and I am using a custom dialog which extends DialogFragment. This dialog will contain certain field that I want to pass to the parent activity. I tried implementing OnDismissListener but the parameter is a Dialog Interface.

                  有什么想法吗?

                  父活动:

                  fab.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              BreakCreator mDialog = new BreakCreator();
                              mDialog.show(getSupportFragmentManager(), "start break Creator");
                  
                          }
                      });
                  

                  听众:

                  @Override
                  public void onDismiss(DialogInterface dialog) {
                      Log.d("debug", "in onDismiss");
                          BreakCreator mBreakCreator = BreakCreator.class.cast(dialog);// This MIGHT not work
                      //TODO cast and shit
                  
                          if(!mBreakCreator.isCancelled() ){
                              int startMinute = mBreakCreator.getStartMinute();
                              int startHour = mBreakCreator.getStartHour();
                              int endMinute = mBreakCreator.getEndMinute();
                              int endHour = mBreakCreator.getEndHour();
                              String day = mBreakCreator.getDay();
                  
                              Break mBreak = new Break(new ultramirinc.champs_mood.Time(startHour, startMinute),
                                      new ultramirinc.champs_mood.Time(endHour, endMinute), day);
                              breakList.add(mBreak);
                              Log.d("created", "break added");
                              recyclerView.invalidate();
                  
                          }else{
                              Log.d("debug", "is not cancelled");
                      }
                  }
                  

                  对话框类:

                  public void onDismiss(final DialogInterface dialog) {
                      super.onDismiss(dialog);
                      final Activity activity = getActivity();
                      if (activity instanceof DialogInterface.OnDismissListener) {
                          ((DialogInterface.OnDismissListener) activity).onDismiss(dialog);
                      }
                  }
                  

                  推荐答案

                  使用自定义监听器,下面是如何实现的示例.Android 开发者指南 中也对此进行了说明.p>

                  Use a custom listener, below is an example on how this could be implemented. This is also explained in the Android Developer Guide.

                  public class CustomDialog extends DialogFragment {
                  
                     public interface CustomListener{
                        void onMyCustomAction(CustomObject co);
                     }
                  
                     private CustomListener mListener;
                  
                     public void setMyCustomListener(CustomListener listener){
                       mListener = listener;
                     }
                  
                     @Override
                     public Dialog onCreateDialog(Bundle savedInstanceState) {
                        ...
                        Code to create dialog 
                        ...
                     }
                  
                     @Override
                     public void onDismiss(DialogInterface dialog) {
                         if(mListener != null){
                            CustomObject o = new CustomObject();
                            mListener.onMyCustomAction(o);
                         }
                         super.onDismiss();
                     }
                  }
                  

                  并在创建自定义对话框时,设置监听器.

                  And when the custom dialog is created, set the listener.

                  CustomDialog awesomeDialog = new CustomDialog();
                  awesomeDialog.setMyCustomListener(new CustomDialog.CustomListener() {
                    @Override
                    public void onMyCustomAction(CustomObject o){
                       Log.i("TAG",o.toString());
                    }
                  });
                  

                  这篇关于使用 onDismiss() 从 DialogFragment 获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android:对话框在 droid 3 上有额外的、丑陋的空间 下一篇:AlertDialog.show 在服务中被忽略

                  相关文章

                  最新文章

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

                      <small id='0PuAy'></small><noframes id='0PuAy'>

                    1. <legend id='0PuAy'><style id='0PuAy'><dir id='0PuAy'><q id='0PuAy'></q></dir></style></legend>
                      • <bdo id='0PuAy'></bdo><ul id='0PuAy'></ul>

                      <tfoot id='0PuAy'></tfoot>