我在底部导航栏上有一个带有图标的家庭活动。单击图标后,它将移动到相应的片段。但问题是家庭活动堆叠在所有碎片上。这可能是什么问题。
我试过完成();在调用片段之后。但这会关闭所有活动并进入主要活动。我需要帮助。
主要活动 - > HomeActivity->出勤片段
这是家庭活动 Home Activity
单击下面的出勤片段 Attendance fragment
以下是家庭活动的代码
public class FHome extends AppCompatActivity {
public static Activity fa;
private Toolbar toolbar;
private ListView listView;
public static SharedPreferences sharedPreferences;
public static String SEL_DAY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fhome);
setupUIViews();
initToolbar();
setupListView();
fa = this;
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.navigation);
bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.action_item1:
selectedFragment = FAttendance.newInstance();
break;
case R.id.action_item2:
selectedFragment = FPost.newInstance();
break;
case R.id.action_item3:
selectedFragment = FUpdate.newInstance();
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;
}
});
//Manually displaying the first fragment - one time only
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, FPost.newInstance());
transaction.commit();
}
帮帮我:(