久久久久久久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(聯系氣泡編輯文本)
主站蜘蛛池模板: 精品欧美一区二区三区久久久 | 国产一区 | 美女啪啪国产 | 亚洲人成一区二区三区性色 | 欧美freesex黑人又粗又大 | 亚洲免费在线 | 热re99久久精品国产99热 | aa级毛片毛片免费观看久 | 九色视频网站 | 国产一级一片免费播放 | 日本aⅴ中文字幕 | 一级看片免费视频 | 国产超碰人人爽人人做人人爱 | 国产精品一区二区三区在线 | 亚洲精品国产电影 | 黄色一级毛片免费看 | 成年免费大片黄在线观看岛国 | 色资源在线 | 日本成人在线观看网站 | 国产精品美女久久久久aⅴ国产馆 | 中文成人无字幕乱码精品 | 91久久精品一区二区二区 | 精品欧美乱码久久久久久1区2区 | 欧日韩在线观看 | 91精品国产一区二区三区香蕉 | 国产精品美女久久久久久免费 | 青青草这里只有精品 | 男人的天堂中文字幕 | 国产探花在线精品一区二区 | 999观看免费高清www | 午夜视频在线 | 国产一区二区三区 | 欧美精品久久久 | 91精品成人久久 | 伊人色综合久久久天天蜜桃 | 欧美日韩电影一区二区 | 欧美1区2区 | 日韩成人一区二区 | 久久高清| 日韩综合在线 | 午夜网站视频 |