diff options
| author | Dianne Hackborn <hackbod@google.com> | 2012-01-25 08:57:43 -0800 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-01-25 08:57:43 -0800 |
| commit | 3c407385303dc44906342147368451f2ef528cff (patch) | |
| tree | 63321b132dd4589ea496ef0fc0d782d490d08d00 | |
| parent | a9c4ae8d3a4cbfab84cf1814def159148692c6bb (diff) | |
| parent | e03f7627874b4f8c0bfa5c302f59a6d0cd83ee40 (diff) | |
| download | android_development-3c407385303dc44906342147368451f2ef528cff.tar.gz android_development-3c407385303dc44906342147368451f2ef528cff.tar.bz2 android_development-3c407385303dc44906342147368451f2ef528cff.zip | |
am e03f7627: am 85241cc7: Add button to clear back stack.
* commit 'e03f7627874b4f8c0bfa5c302f59a6d0cd83ee40':
Add button to clear back stack.
3 files changed, 26 insertions, 5 deletions
diff --git a/samples/Support4Demos/res/layout/fragment_stack.xml b/samples/Support4Demos/res/layout/fragment_stack.xml index 1d12496ac..0f0951fd6 100644 --- a/samples/Support4Demos/res/layout/fragment_stack.xml +++ b/samples/Support4Demos/res/layout/fragment_stack.xml @@ -28,11 +28,19 @@ android:layout_weight="1"> </FrameLayout> - <Button android:id="@+id/new_fragment" + <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="0" - android:text="@string/new_fragment"> - <requestFocus /> - </Button> + android:layout_weight="0" android:orientation="horizontal"> + <Button android:id="@+id/home" + android:layout_width="wrap_content" android:layout_height="wrap_content" + android:text="@string/home"> + <requestFocus /> + </Button> + <Button android:id="@+id/new_fragment" + android:layout_width="wrap_content" android:layout_height="wrap_content" + android:text="@string/new_fragment"> + <requestFocus /> + </Button> + </LinearLayout> </LinearLayout> diff --git a/samples/Support4Demos/res/values/strings.xml b/samples/Support4Demos/res/values/strings.xml index 4738c44aa..8cd91f6fb 100644 --- a/samples/Support4Demos/res/values/strings.xml +++ b/samples/Support4Demos/res/values/strings.xml @@ -77,6 +77,7 @@ <string name="fragment_receive_result_support">Fragment/Receive Result</string> <string name="fragment_stack_support">Fragment/Stack</string> + <string name="home">Go home</string> <string name="new_fragment">New fragment</string> <string name="fragment_tabs">Fragment/Tabs</string> diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java index c4d05fa9f..337f2c120 100644 --- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java +++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStackSupport.java @@ -20,6 +20,7 @@ import com.example.android.supportv4.R; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.os.Bundle; @@ -45,6 +46,17 @@ public class FragmentStackSupport extends FragmentActivity { addFragmentToStack(); } }); + button = (Button)findViewById(R.id.home); + button.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + // If there is a back stack, pop it all. + FragmentManager fm = getSupportFragmentManager(); + if (fm.getBackStackEntryCount() > 0) { + fm.popBackStack(fm.getBackStackEntryAt(0).getId(), + FragmentManager.POP_BACK_STACK_INCLUSIVE); + } + } + }); if (savedInstanceState == null) { // Do first time initialization -- add initial fragment. |
