I have a fragment with a list of items. When an item is clicked I need to show the details of that item in another fragment. Basically I am looking for something similar to calling a new activity from another activity. Since I am using fragments, I always use the below code to show another fragment from one fragment:
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment fragment = new LoginFragment();
transaction.replace(R.id.login_Or_FeatureContainer, fragment);
transaction.commit();
In above example I am replacing a layout for new content to be presented.
Is there any other option than replacing?
As I am not sure how to switch from one fragment to another for my scenario explained above I am trying to use ViewSwitcher as given below:
<ViewSwitcher
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/viewSwitcher" >
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.fragments.ItemFragment"
android:id="@+id/fragment"
tools:layout="@layout/fragment_item" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.fragments.Fragment_Offer_Voucher_Detail"
android:id="@+id/fragment2"
tools:layout="@layout/fragment_offer_detail" />
</ViewSwitcher>
Here I am trying to switch to next fragment using view switcher. But my second fragment is dynamic -- the data depends on the item clicked in first fragment.
So is it possible to dynamically load another fragment using ViewSwitcher?
Thanks.