• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.app;
18 
19 import com.example.android.apis.R;
20 
21 import android.app.Fragment;
22 import android.app.FragmentTransaction;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 
28 /**
29  * Demonstrates a fragment that can be configured through both Bundle arguments
30  * and layout attributes.
31  */
32 public class FragmentArgumentsFragment extends Fragment {
onCreate(Bundle savedInstanceState)33     @Override public void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35 
36         if (savedInstanceState == null) {
37             // First-time init; create fragment to embed in activity.
38             FragmentTransaction ft = getChildFragmentManager().beginTransaction();
39             Fragment newFragment = FragmentArguments.MyFragment.newInstance("From Arguments 1");
40             ft.add(R.id.created1, newFragment);
41             newFragment = FragmentArguments.MyFragment.newInstance("From Arguments 2");
42             ft.add(R.id.created2, newFragment);
43             ft.commit();
44         }
45     }
46 
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)47     @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
48             Bundle savedInstanceState) {
49         View v = inflater.inflate(R.layout.fragment_arguments_fragment, container, false);
50         return v;
51     }
52 //END_INCLUDE(create)
53 }
54