J'essaie de faire une activité contenant deux fragments. Le premier a 3 fragments imbriqués que je vais utiliser comme onglets et le second contient seulement des boutons. Je ne veux pas ajouter le fragment de boutons dans d'autres framents parce que je ne veux pas le recharger. En ce moment je n'ai pas d'erreurs mais mon fragment de boutons ne se présente pas. Voici mes fragments et mon activité.Fragment n'apparaît pas
mon activité principale:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
Fragment statistics = new StatisticsFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_statistics, statistics).commit();
Fragment buttons = new MainPageButtonsFragment();
FragmentTransaction buttonsTransaction = getSupportFragmentManager().beginTransaction();
buttonsTransaction.add(R.id.main_page_buttons_fragment,buttons).commit();
sa mise en page
<RelativeLayout android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragment_statistics"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/main_page_buttons_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/fragment_statistics"/>
J'écris wont mon fragment de boutons, car il ne faut pas que je dirai seulement sa balise racine est FrameLayout
.
mes statistiques fragment (avec onglets)
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Fragment currentDayFragment = new CurrentDayFragment();
FragmentTransaction transaction1 = getChildFragmentManager().beginTransaction();
transaction1.add(R.id.current_day_fragment, currentDayFragment).commit();
Fragment configurationInfoFragment = new ConfigurationInfoFragment();
FragmentTransaction transaction2 = getChildFragmentManager().beginTransaction();
transaction2.add(R.id.configuration_info_fragment, configurationInfoFragment).commit();
Fragment expensesInfoFragment = new ExpensesInfoFragment();
FragmentTransaction transaction3 = getChildFragmentManager().beginTransaction();
transaction3.add(R.id.expenses_info_fragment, expensesInfoFragment).commit();
LayoutInflater lf = getActivity().getLayoutInflater();
View statisticsView = lf.inflate(R.layout.fragment_statistics, container, false);
return statisticsView;
}
sa mise en page:
<FrameLayout >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@id/current_day_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@id/configuration_info_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@id/expenses_info_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.v4.view.ViewPager>
les fragments imbriqués ont juste balise racine FrameLayout
et deux TextView
s en elle. Le résultat est juste une activité avec 3 onglets et aucun fragment de boutons. Je suis nouveau à la programmation Android et je suis complètement perdu dans ce domaine. Aidez-moi, s'il vous plaît!
C'est ok maintenant! Tu es l'homme! – Angel