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

防止在Android中的屏幕旋轉對話框解除

Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
本文介紹了防止在Android中的屏幕旋轉對話框解除的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

I am trying to prevent dialogs built with Alert builder from being dismissed when the Activity is restarted.

If I overload the onConfigurationChanged method I can successfully do this and reset the layout to correct orientation but I lose sticky text feature of edittext. So in solving the dialog problem I have created this edittext problem.

If I save the strings from the edittext and reassign them in the onCofiguration change they still seem to default to initial value not what was entered before rotation. Even if I force an invalidate does seem to update them.

I really need to solve either the dialog problem or the edittext problem.

Thanks for the help.

解決方案

The best way to avoid this problem nowadays is by using a DialogFragment.

Create a new class which extends DialogFragment. Override onCreateDialog and return your old Dialog or an AlertDialog.

Then you can show it with DialogFragment.show(fragmentManager, tag).

Here's an example with a Listener:

public class MyDialogFragment extends DialogFragment {

    public interface YesNoListener {
        void onYes();

        void onNo();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (!(activity instanceof YesNoListener)) {
            throw new ClassCastException(activity.toString() + " must implement YesNoListener");
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setTitle(R.string.dialog_my_title)
                .setMessage(R.string.dialog_my_message)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ((YesNoListener) getActivity()).onYes();
                    }
                })
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ((YesNoListener) getActivity()).onNo();
                    }
                })
                .create();
    }
}

And in the Activity you call:

new MyDialogFragment().show(getSupportFragmentManager(), "tag"); // or getFragmentManager() in API 11+

This answer helps explain these other three questions (and their answers):

  • Android Best way of avoid Dialogs to dismiss after a device rotation
  • Android DialogFragment vs Dialog
  • How can I show a DialogFragment using compatibility package?

這篇關于防止在Android中的屏幕旋轉對話框解除的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
Contact Bubble EditText(聯系氣泡編輯文本)
主站蜘蛛池模板: 亚洲国产中文字幕 | 激情 婷婷 | 天天操人人干 | 久久机热 | 欧美三级视频 | 国产一区亚洲 | 国产精品久久久久久久久久久免费看 | 亚洲欧美中文日韩在线v日本 | 在线中文视频 | 夜夜操av| 青青草av | 久久久国产一区二区三区 | av毛片在线| 亚洲男人天堂av | 久久99精品久久久久久 | 国产探花在线精品一区二区 | 国产一区二区在线播放视频 | 国产三级在线观看播放 | 国产一区二区三区久久久久久久久 | 精品国产一区二区三区av片 | 亚洲国产精品一区 | 日批免费看 | 久久夜视频 | 日韩精品一区二区三区在线播放 | 欧美日日| 精品久久精品 | 精品小视频 | 日韩在线一区视频 | 亚洲成人午夜电影 | 国产ts人妖一区二区三区 | 中文字幕国产一区 | 亚洲欧美激情精品一区二区 | 中文字幕不卡视频在线观看 | 成人网址在线观看 | 欧美在线观看免费观看视频 | 午夜噜噜噜 | www国产亚洲精品久久网站 | 欧美啪啪 | 九一国产精品 | 国产观看| 日韩欧美一区二区三区四区 |