• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package android.support.v7.app;
2 /*
3  * Copyright (C) 2016 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 import android.os.Bundle;
19 import android.support.annotation.Nullable;
20 import android.support.v4.app.Fragment;
21 import android.support.v7.appcompat.test.R;
22 import android.support.v7.testutils.BaseTestActivity;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 
27 
28 public class FragmentContentIdActivity extends BaseTestActivity {
29 
30     @Override
onCreate(Bundle savedInstanceState)31     protected void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33 
34         getSupportFragmentManager().beginTransaction()
35                 .add(android.R.id.content, new FragmentA())
36                 .commit();
37     }
38 
39     @Override
getContentViewLayoutResId()40     protected int getContentViewLayoutResId() {
41         // We don't want to set a layout
42         return 0;
43     }
44 
replaceWithFragmentB()45     public void replaceWithFragmentB() {
46         getSupportFragmentManager().beginTransaction()
47                 .replace(android.R.id.content, new FragmentB())
48                 .commit();
49     }
50 
51     public static class FragmentA extends Fragment {
52         @Override
onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)53         public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
54                 @Nullable Bundle savedInstanceState) {
55             View view = new View(getContext());
56             view.setId(R.id.fragment_a);
57             return view;
58         }
59     }
60 
61     public static class FragmentB extends Fragment {
62         @Nullable
63         @Override
onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)64         public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
65                 @Nullable Bundle savedInstanceState) {
66             View view = new View(getContext());
67             view.setId(R.id.fragment_b);
68             return view;
69         }
70     }
71 
72 }
73 
74 
75 
76