At com. Example. Myapplication. LoginActivity. OnCreate (LoginActivity. Java: 38)
The corresponding local
GetSupportFragmentManager (). The beginTransaction (). The add (R.i d.f ragment_container, fristFragment), show (fristFragment). The commit ();
The entire source code
Package com. Example. Myapplication;
The import androidx. Appcompat. App. AppCompatActivity;
The import androidx. Fragments. App. Fragments;
The import androidx. Fragments. App. FragmentTransaction;
The import android. Content. Intent;
The import android. OS. Bundle;
The import android. View. The view;
The import android. Widget. LinearLayout;
The import android. Widget. TextView;
The import fragments. FouthFragment;
The import fragments. FristFragment;
The import fragments. SecondFragment;
The import fragments. ThirdFragment;
Public class LoginActivity extends AppCompatActivity implements the View. An OnClickListener {
Private fragments [] mfragments;
Private FristFragment FristFragment;
Private SecondFragment SecondFragment;
Private ThirdFragment ThirdFragment;
Private FouthFragment FouthFragment;
Private int index;
Private int currentTabIndex;
Private static final ints FRAGMENT_frist=0;
Private static final ints FRAGMENT_second=1;
Private static final ints FRAGMENT_third=2;
Private static final ints FRAGMENT_fouth=3;
Private LinearLayout [] mTabs;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_login);
Mfragments=new fragments [] {fristFragment secondFragment, thirdFragment, fouthFragment};
GetSupportFragmentManager (). The beginTransaction (). The add (R.i d.f ragment_container, fristFragment), show (fristFragment). The commit ();
MTabs=new LinearLayout [mfragments length];
MTabs [FRAGMENT_frist]=the findViewById (R.i d.f ragment_frist);
MTabs [FRAGMENT_second]=the findViewById (R.i d.f ragment_second);
MTabs [FRAGMENT_third]=the findViewById (R.i d.f ragment_third);
MTabs [FRAGMENT_fouth]=the findViewById (R.i d.f ragment_fouth);
MTabs [FRAGMENT_frist] setOnClickListener (this);
MTabs [FRAGMENT_second] setOnClickListener (this);
MTabs [FRAGMENT_third] setOnClickListener (this);
MTabs [FRAGMENT_fouth] setOnClickListener (this);
MTabs [FRAGMENT_frist] setSelected (true);
}
@ Override
Public void onClick (View v)
Can know where is wrong for me have a look at it
thank you
CodePudding user response:
Do you changeFragmentManager FM=getSupportFragmentManager ();
FragmentTransaction transaction=FM. BeginTransaction ();
Transaction. The replace (R.i d.f ragment_container fristFragment);
Transaction.com mitAllowingStateLoss ();
//this section to remove
Show (fristFragment)
Let me see your best XML code
CodePudding user response:
The