0

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 fragmentbased on which ActionTabis 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();
}
}
4

1 回答 1

1

isVisible()适用于您在物理上删除可能不再需要的视图时;绑定到 View.Visible、View.Invisible、View.Gone。因此,您最好检查所选选项卡以了解您正在做什么。

此外,根据您的要求,您可以简单地从 Activity 中轻松找到 ActionBar,并根据您的后续问题进行如下小修改:

actionBar_ = getActionBar();
            actionBar_.setSubtitle("subtitle");
            actionBar_.setTitle("title");
            actionBar_.setDisplayHomeAsUpEnabled(true);//If navigation from home needed
            actionBar_.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#BB000000")));  //Allow for some transparency in the ActionBar.
于 2013-05-07T18:50:43.343 回答