久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='HjonV'></tfoot>

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

  • <legend id='HjonV'><style id='HjonV'><dir id='HjonV'><q id='HjonV'></q></dir></style></legend>

    <i id='HjonV'><tr id='HjonV'><dt id='HjonV'><q id='HjonV'><span id='HjonV'><b id='HjonV'><form id='HjonV'><ins id='HjonV'></ins><ul id='HjonV'></ul><sub id='HjonV'></sub></form><legend id='HjonV'></legend><bdo id='HjonV'><pre id='HjonV'><center id='HjonV'></center></pre></bdo></b><th id='HjonV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HjonV'><tfoot id='HjonV'></tfoot><dl id='HjonV'><fieldset id='HjonV'></fieldset></dl></div>
      <bdo id='HjonV'></bdo><ul id='HjonV'></ul>
      1. 方向更改時(shí)的 DialogFragment 回調(diào)

        DialogFragment callback on orientation change(方向更改時(shí)的 DialogFragment 回調(diào))
      2. <legend id='TQBmk'><style id='TQBmk'><dir id='TQBmk'><q id='TQBmk'></q></dir></style></legend>
      3. <i id='TQBmk'><tr id='TQBmk'><dt id='TQBmk'><q id='TQBmk'><span id='TQBmk'><b id='TQBmk'><form id='TQBmk'><ins id='TQBmk'></ins><ul id='TQBmk'></ul><sub id='TQBmk'></sub></form><legend id='TQBmk'></legend><bdo id='TQBmk'><pre id='TQBmk'><center id='TQBmk'></center></pre></bdo></b><th id='TQBmk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TQBmk'><tfoot id='TQBmk'></tfoot><dl id='TQBmk'><fieldset id='TQBmk'></fieldset></dl></div>
          <bdo id='TQBmk'></bdo><ul id='TQBmk'></ul>

              • <tfoot id='TQBmk'></tfoot>

                    <tbody id='TQBmk'></tbody>

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

                1. 本文介紹了方向更改時(shí)的 DialogFragment 回調(diào)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在遷移當(dāng)前使用 Activity.showDialog(DIALOG_ID); 的對(duì)話框,以使用 android參考.

                  I'm migrating my dialogs, currently using Activity.showDialog(DIALOG_ID);, to use the DialogFragment system as discussed in the android reference.

                  在我的開(kāi)發(fā)過(guò)程中,使用回調(diào)將某些事件傳遞回打開(kāi)對(duì)話框的活動(dòng)/片段時(shí)出現(xiàn)了一個(gè)問(wèn)題:

                  There's a question that arose during my development when using callbacks to deliver some event back to the activity/fragment that opened the dialog:

                  這是一個(gè)簡(jiǎn)單對(duì)話框的示例代碼:

                  Here's some example code of a simple dialog:

                  public class DialogTest extends DialogFragment {
                  
                  public interface DialogTestListener {
                      public void onDialogPositiveClick(DialogFragment dialog);
                  }
                  
                  // Use this instance of the interface to deliver action events
                  static DialogTestListener mListener;
                  
                  public static DialogTest newInstance(Activity activity, int titleId, int messageId) {
                      udateListener(activity);
                      DialogTest frag = new DialogTest();
                      Bundle args = new Bundle();
                      args.putInt("titleId", titleId);
                      args.putInt("messageId", messageId);
                      frag.setArguments(args);
                      return frag;
                  }
                  
                  public static void udateListener(Activity activity) {
                      try {
                          // Instantiate the NoticeDialogListener so we can send events with it
                          mListener = (DialogTestListener) activity;
                      } catch (ClassCastException e) {
                          // The activity doesn't implement the interface, throw exception
                          throw new ClassCastException(activity.toString() + " must implement DialogTestListener");
                      }
                  }
                  
                  
                  @Override
                  public Dialog onCreateDialog(Bundle savedInstanceState) {
                      int titleId = getArguments().getInt("titleId");
                      int messageId = getArguments().getInt("messageId");
                  
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                      // dialog title
                      builder.setTitle(titleId);
                      // dialog message
                      builder.setMessage(messageId);
                  
                      // dialog negative button
                      builder.setNegativeButton("No", new OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {}});
                      // dialog positive button
                      builder.setPositiveButton("Yes", new OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              mListener.onDialogPositiveClick(DialogTest.this);
                          }});
                  
                      // create the Dialog object and return it
                      return builder.create();
                  }}
                  

                  下面是一些調(diào)用它的活動(dòng)代碼:

                  And here's some activity code calling it:

                  public class SomeActivity extends FragmentActivity implements DialogTestListener {
                  private EditText mUserName;
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      // setup ui
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.ui_user_edit);
                      // name input
                      mUserName = (EditText) findViewById(R.id.userEdit_editTextName);
                  }
                  
                  @Override
                  public void onDialogPositiveClick(DialogFragment dialog) {
                      Log.d(TAG, this.toString());
                      mUserName.setText(mUserName.getText() + "1");
                  }
                  
                  private void showDialog() {
                      DialogTest test = DialogTest.newInstance(SomeActivity.this, R.string.someTitleText, R.string.someMessageText);
                      test.show(getSupportFragmentManager(), "testDialog");
                  }}
                  

                  代碼幾乎就是您所看到的參考.問(wèn)題是,一旦您進(jìn)行方向更改,當(dāng)顯示對(duì)話框時(shí),它會(huì)按預(yù)期停止工作-->由于活動(dòng)生命周期,活動(dòng)和對(duì)話框都被重建,對(duì)話框現(xiàn)在沒(méi)有正確的引用新的重建活動(dòng).

                  The code is pretty much what you see the reference. Problem is, that once you do a orientation change, when a dialog is shown, it stops working as expected --> Due to the activity lifecycle, both, the activity and the dialog are rebuild, and the dialog now does not have the proper reference to the new rebuilt activity.

                  我在我的活動(dòng) onResume 方法中添加了以下代碼:

                  I added the following code to my activitys onResume method:

                      @Override
                  protected void onResume() {
                      super.onResume();
                      DialogTest.udateListener(this);
                  }
                  

                  這樣做,我得到了預(yù)期的行為,當(dāng)方向改變發(fā)生時(shí),對(duì)話框?qū)⑹录l(fā)送回新的重建活動(dòng).

                  Doing this, I get the expected behavior, and the dialog sends events back to the new rebuilt activity when an orientation change occured.

                  我的問(wèn)題是:處理在方向更改期間由 FragmentActivity 打開(kāi)的 DialogFragment 之間的回調(diào)的最佳實(shí)踐"是什么?

                  My question is: What is the 'best practice' to handle the callbacks between the DialogFragment which was opened by a FragmentActivity during an orientation change?

                  最好的問(wèn)候

                  推薦答案

                  是的,這是我自己一直陷入的常見(jiàn)陷阱.首先讓我說(shuō),您在 onResume() 中調(diào)用 DialogTest.udateListener() 的解決方案似乎完全適合我.

                  Yeah, this is a common trap I'm falling in all the time myself. First of all let me say that your solution of calling DialogTest.udateListener() in onResume() seems to be fully appropriate to me.

                  另一種方法是使用 ResultReceiver,它可以序列化為 Parcelable:

                  An alternative way would be to use a ResultReceiver which can be serialized as a Parcelable:

                  public class DialogTest extends DialogFragment {
                  
                  public static DialogTest newInstance(ResultReceiver receiver, int titleId, int messageId) {
                      DialogTest frag = new DialogTest();
                      Bundle args = new Bundle();
                      args.putParcelable("receiver", receiver);
                      args.putInt("titleId", titleId);
                      args.putInt("messageId", messageId);
                      frag.setArguments(args);
                      return frag;
                  }
                  
                  @Override
                  public Dialog onCreateDialog(Bundle savedInstanceState) {
                      int titleId = getArguments().getInt("titleId");
                      int messageId = getArguments().getInt("messageId");
                      ResultReceiver receiver = getArguments().getParcelable("receiver");
                  
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                      // dialog title
                      builder.setTitle(titleId);
                      // dialog message
                      builder.setMessage(messageId);
                  
                      // dialog negative button
                      builder.setNegativeButton("No", new OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              receiver.sendResult(Activity.RESULT_CANCEL, null);
                          }});
                      // dialog positive button
                      builder.setPositiveButton("Yes", new OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              receiver.sendResult(Activity.RESULT_OK, null);
                          }});
                  
                      // create the Dialog object and return it
                      return builder.create();
                  }}
                  

                  然后您可以像這樣處理 Receiver 中的所有內(nèi)容:

                  Then you can handle everything in the Receiver like this:

                  protected void onReceiveResult(int resultCode, Bundle resultData) {
                      if (getActivity() != null){
                          // Handle result
                      }
                  }
                  

                  查看 ResultReceiver 無(wú)法適應(yīng)屏幕旋轉(zhuǎn)了解更多詳情.所以最后你可能仍然需要用你的 Activity 重新連接 ResultReceiver.唯一的區(qū)別是您將 ActivityDialogFragment 解耦.

                  Check out ResultReceiver doesn't survire to screen rotation for more details. So in the end you probably still need to rewire the ResultReceiver with your Activity. The only difference is that you decouple the Activity from the DialogFragment.

                  這篇關(guān)于方向更改時(shí)的 DialogFragment 回調(diào)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                  Get current location during app launch(在應(yīng)用啟動(dòng)期間獲取當(dāng)前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)
                  <legend id='GodVg'><style id='GodVg'><dir id='GodVg'><q id='GodVg'></q></dir></style></legend>
                2. <small id='GodVg'></small><noframes id='GodVg'>

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

                              <tbody id='GodVg'></tbody>

                            <tfoot id='GodVg'></tfoot>
                            主站蜘蛛池模板: 午夜在线免费观看 | 在线国产视频 | 久久99精品久久久久久国产越南 | 国产精品一区二区无线 | 亚洲性视频网站 | 国产成人精品一区二区三区四区 | 四虎永久影院 | 久久高清 | 一区二区精品 | 日韩欧美在线视频一区 | 亚洲一区欧美 | 欧美精品一区二区在线观看 | 国产欧美一区二区三区久久 | 伊人狠狠 | 亚洲精品国产电影 | 成人日b视频| 亚洲一区二区三 | 国产精品揄拍一区二区 | 亚洲视频二区 | 日韩无| 国产美女在线观看 | 日韩有码在线播放 | 国产高清一二三区 | 亚洲视频在线一区 | 国产人免费人成免费视频 | 理论片午午伦夜理片影院 | 日韩欧美国产精品一区二区 | 一区二区视频免费观看 | 日韩一区二区久久 | 一区二区三区精品在线视频 | 日韩a v在线免费观看 | 欧美成人精品激情在线观看 | 韩日免费视频 | 精国产品一区二区三区四季综 | 欧美亚洲免费 | 日韩一区二区三区av | 亚洲视频一区在线播放 | 欧美综合久久久 | 91在线免费观看网站 | 欧美激情久久久 | 精品久久九九 |