码迷,mamicode.com
首页 > 其他好文 > 详细

解决dialog在横竖屏切换时消失

时间:2014-12-10 10:57:07      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:解决dialog在横竖屏切换时消失

以AlertDialog为例

   一、将AlertDialog视图封装在dialogfragment(fragmentdeAlertDialog子类)实例中

 

    package com.example.t;

    import android.app.AlertDialog;            
    import android.app.Dialog;
    import android.os.Bundle;
    import android.widget.DatePicker;

    public class DialogPickerFragment extends android.support.v4.app.DialogFragment {
       @Override
       public Dialog onCreateDialog(Bundle savedInstanceState) {
            DatePicker dp = new DatePicker(getActivity());
            return new AlertDialog.Builder(getActivity())
            .setView(dp)
            .setTitle("Dialog")
            .setPositiveButton("OK", null)
            .create();
         }
    }

 

  二、在activity中调用

    public void dialogpicker(View v) {
          FragmentManager fm = getSupportFragmentManager();
          DialogPickerFragment dialog = new DialogPickerFragment();
          dialog.show(fm, "date");
    }

 

解决dialog在横竖屏切换时消失

标签:解决dialog在横竖屏切换时消失

原文地址:http://9437752.blog.51cto.com/9427752/1588135

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!