Strange FragmentTransaction in the FragmentLayout class from the ApiDemos sample

Sorry, this question is for those of you who are working on Eclipse with access to ApiDemo code samples .
In particular, I am trying to base a fragment operation on a FragmentLayout sample

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(); 

I have two questions:

  • What is the difference between index == 0 and index != 0 ?

  • The R.id_a_item resource (only appearing in all ApiDemos after searching for it) refers to some menu shortcut resource, which is not entirely clear why it is used here.

The android.developers manual does not explain this bit of code.

+7
source share
1 answer

What is the difference between index == 0 and index! = 0?

There should be no difference between position 0 and other list items, since for this code you just need to replace a fragment of the previous part with a new one.

The resource R.id_a_item (only appearing in all ApiDemos, after searching for it) belongs to some resource of menu shortcuts, and it is not clear why it is used here.

Most likely, this is an error in the example, since using this id will throw an exception because it does not exist in the current layout (I launched the API Demos project found on emulator 4.2 and it throws this view of the found exception ... etc . for this id). It is likely that slippage in the latest version of the samples as a code fragment of your survey does not exist in other versions.

+5
source

All Articles