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

防止在Android中的屏幕旋轉(zhuǎn)對話框解除

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

問題描述

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?

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

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

相關(guān)文檔推薦

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 操作標(biāo)簽的多行 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 設(shè)置為僅接受 Android 中的數(shù)值?)
Contact Bubble EditText(聯(lián)系氣泡編輯文本)
主站蜘蛛池模板: 亚洲精品成人 | 亚洲777 | 青青草精品 | 青青草视频免费在线观看 | 色婷婷香蕉在线一区二区 | 亚洲国产一区在线 | 亚洲自拍偷拍视频 | 亚洲精品一区二区三区精华液 | 中文字幕在线免费看 | 国产又粗又猛又黄又爽的视频 | 亚洲二三区 | 女人高潮特级毛片 | 亚洲欧美日韩一区二区 | 手机在线毛片 | 国产日韩欧美 | 欧美日韩在线精品 | 日本一区二区在线播放 | av在线一区二区三区 | 国产第二页 | 久久久久久国产精品 | 天天摸夜夜操 | 中文字幕第一区综合 | 超碰男人的天堂 | 九色自拍 | 99热国产 | 中文字幕国产视频 | av每日更新 | 五月婷婷深深爱 | 成人小视频在线观看 | 青青草视频网站 | 久久a视频| 精品欧美黑人一区二区三区 | 久久免费观看视频 | 日韩视频在线免费观看 | 中国av在线 | 天堂网久久 | 中文字幕在线免费观看 | 中国a一片一级一片 | 成人黄性视频 | 欧美狠狠干 | 久久综合五月天 |