使用 DialogFragment 并制作您自己的对话框布局。
使用 FragmentActivity 扩展您的活动
因为 getSupportFragmentManager() 仅适用于 FragmentActivity
//dialog.setArguments(bundle); if you want to pass values with bundle then use this
如果你想从 FragmentActivity 显示 dialof 使用:
DialogFragment newFragment = H_Calendar_UserScheduleEditFragment
.newInstance(b);
newFragment.show(getSupportFragmentManager(), "dialog");
如果你想从片段中显示它:
DialogFragment newFragment = H_Calendar_UserScheduleEditFragment
.newInstance(b);
/** Getting callback from dialog fragment by set target fragment **/
newFragment.setTargetFragment(H_UserCalanderFragment.this, 0);
newFragment.show(getFragmentManager(), "dialog");
public class H_Calendar_UserScheduleEditFragment extends DialogFragment {
Bundle b;
public static H_Calendar_UserScheduleEditFragment newInstance(Bundle b) {
H_Calendar_UserScheduleEditFragment hschedule = new H_Calendar_UserScheduleEditFragment();
hschedule.setArguments(b);
return hschedule;
}
use this method if you want some callback in Activity:
Create your own listner and just pass Activity refrence or fragment refrence to to your listner refrence variable. And on completion or cancelation of dialog do whatever you want from your listner to do.
// Override the Fragment.onAttach() method to instantiate the
// NoticeDialogListener
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Bundle notificationBundle = getArguments();
// Instantiate the NoticeDialogListener so we can send events to the
// host
//this.mListener = (NoticeDialogListener) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement NoticeDialogListener");
}
}
Use this if you want callback in Fragment:
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
//this.mListener = (NoticeDialogListener) getTargetFragment();
} catch (final ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnCompleteListener");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//To make your dialg fragment to see on full screen , then incude this
getActivity().getWindow().setLayout(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
int style = DialogFragment.STYLE_NO_FRAME;
int theme = R.style.CustomizeDialog;
// int theme = android.R.style.Theme_Wallpaper;
setStyle(style, theme);
b = getArguments();
}
include this style in your style.xml
<style name="CustomizeDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
Now in oncreate view
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(
R.layout.my_schedule_calander_userupdatedelete, container,
false);
FindId(v);
SetListner();
return v;
}
///这是从片段或活动创建自己的对话框的所有过程。
现在你必须实现检查选择的逻辑
选中列表视图中的复选框,并在顶部单独设置一个。
检查是否选择了顶部检查选择列表视图的所有复选框。
否则在 listview 中监听检查选项。如果出现任何问题,请尝试让我知道