Add button to clear back stack.
Change-Id: I4f02714ec349055a486608ff0eab75a46d6ba7cd
This commit is contained in:
@@ -28,11 +28,19 @@
|
||||
android:layout_weight="1">
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
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:layout_weight="0"
|
||||
android:text="@string/new_fragment">
|
||||
<requestFocus />
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user