I am sorry, this question is for those of you working on Eclipse with access to the ApiDemo sample codes.
Specifically, I am trying to base a fragment activity on the sample called FragmentLayout
The following code is problematic for me (you can find the full code in ApiDemo FragmentLayout.java, ShowDetails() method):
// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (index == 0) {
ft.replace(R.id.details, details);
} else {
ft.replace(R.id.a_item, details);
}
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
Two questions I have:
What's the difference between index == 0
and index != 0
?
The resource R.id_a_item (only occurence in all ApiDemos, after searching it) belongs to some kind of menu shortcut resource, not clear at all why it is used here.
The android.developers guide does not explain this bit of code.
What's the difference between index == 0 and index != 0 ?
There shouldn't be any differences between position 0
and the other positions of the list as the code is set to simply replace the previous details fragment with a new one.
The resource R.id_a_item (only occurence in all ApiDemos, after searching it) belongs to some kind of menu shortcut resource, not clear at all why it is used here.
Most likely that is an error in the sample as using that id will throw an exception because it doesn't exist in the current layout(I've run the API Demos
project found on the 4.2 emulator and it throws that no view found exception...etc for that id). Probably a slip in the last version of the samples as the piece of code your questioning doesn't exist in other versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With