So I am using a custom dialog fragment
, when it pops up it asks a question and when the positive response "yes" is selected I want to load a specific fragment
based on which ActionTab
is selected. 显然,现在代码只加载 1 个默认值fragment
,但我将实现一个 switch 语句来检查哪个Tab
被选中或哪个fragment
当前可见。我的问题是有这样做的首选method
吗?就像选择.isVisible()
,fragment
或使用.getSelectedTab()
method
当前ActionTab
。
这是我的代码,提前感谢您的时间
当前的.java
public class StoreDialog_Fragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder storeD = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
storeD.setView(inflater.inflate(R.layout.fragment_store_dialog, null))
.setMessage(R.string.store_question)
.setPositiveButton(R.string.yes_q,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// switch statement here
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.replace(R.id.header_fragment_container,
new Assets_Fragment());
ft.commit();
}
})
.setNegativeButton(R.string.no_q,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// No it isn't!
}
});
// Create the Dialog object and return it
return storeD.create();
}
}