I'm dealing with my first Android app and I'm a bit lost right now.
I have a ListView, and when the user clicks on one element from this list, a detail view should appear. I wouldn't be any trouble but my app will run on both tablet and phone, and I want to show this detail view modally on tablet and normally (using fragmentManager.beginTransaction().add(...)) on phone.
I know how to create a DialogFragment (in fact, I use one somewhere else in the app), but I'm not sure if a DialogFragment can be use with a normal transaction.
And I don't know how can distinguish if my app is running on phone or tablet (apart of creating a layout inside a layout-sw600dp folder)
EDIT
Well, thanks to the answer of Margarita I reached a solution (not the only one, but one of some possibilities).
1) Define B as a DialogFragment
2) Create a values.xml inside res/values folder with this code
<bool name="isTablet">false</bool>
3) Create another values.xml inside res/values-sw600dp folder with this code.This way, I have a boolean resource telling me if the app is running on a tablet.
<bool name="isTablet">true</bool>
4) On Fragment A (who is in charge of showing Fragment B), create a method similar to this:
private void showFragmentB(){
Resources res = getResources();
boolean isTablet = res.getBoolean(R.bool.isTablet);
if (isTablet) {
// We're running on a tablet, so we show Fragment B as a dialog
FragmentB.newInstance().show(getActivity().getSupportFragmentManager(), FragmentB.class.toString());
} else {
// We're running on a phone, adding Fragment B to the stack
// with some animation
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom);
transaction.add(R.id.container, FragmentB.newInstance(), FragmentB.class.toString());
transaction.addToBackStack(FragmentB.class.toString());
transaction.commit();
}
}
5) Call that method whenever Fragment B should appear.
Thanks for helping me.