我有一個片段類,它具有操作欄圖標。它是這樣的 -從一個片段Android啓動對話框片段
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.action_bar_call, menu);
super.onCreateOptionsMenu(menu,inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
//Call Dialog fragment from here
CallDialogFragment dialog = CallDialogFragment .instantiate(getActivity(), "fragmentTAG");
dialog.show(getFragmentManager(), "dialog");
return false;
}
return false;
}
編輯:
public class CallDialogFragment extends DialogFragment {
public CallDialogFragment() {
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
View view = getActivity().getLayoutInflater().inflate(R.layout.call_dialog_fragment, new LinearLayout(getActivity()), false);
// Build dialog
Dialog builder = new Dialog(getActivity());
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
builder.setContentView(view);
return builder;
}
}
TheDialogFragment類看起來是這樣的。我在我的片段說法不兼容的類型
如何調用對話片段與片段
http://android-developers.blogspot.com/2012/05/using-dialogfragments.html?m=1 – Mariusz
我不知道爲什麼下跌投票...仍然沒有令人信服的答案 –
「不兼容的類型所需:xyzCallDialog找到:android.app.Fragment」tl; dr改變「CallDialogFragment對話框= CallDialogFragment .instantiate(getActivity(),」fragmentTAG「); ''到對話框DialogFragment =新CallDialogFragment();' – Mariusz