Reputation: 339
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. Obviously right now the code just loads 1 default fragment
but I would be implementing a switch statement that checked either which Tab
was selected or which fragment
was currently visible. My question is there a preferred method
for doing this? As in selecting .isVisible()
for the fragment
, or using the .getSelectedTab()
method
for the current ActionTab
.
Here is my code, and thank you in advance for your time
current .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();
}
}
Upvotes: 0
Views: 95
Reputation: 4338
isVisible()
is for when you are physically removing a view that you may not need anymore until later; tied to View.Visible, View.Invisible, View.Gone. So you would be better off checking against the selected tab for what you are doing.
Additionally, as per your request you can simply find the ActionBar from the Activity easy enough and make small modifications like the following as per your followup question:
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.
Upvotes: 1