解决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在横竖屏切换时消失
URL地址:http://myzitong.com/article/gehego.html