public void handleChangeFragment(View view) {
Log.e("123","123");
Fragment selectedFragment;
if(view == findViewById(R.id.dairy)){
selectedFragment = new milkFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(view == findViewById(R.id.meat)){
selectedFragment = new meatFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(view == findViewById(R.id.veg)){
selectedFragment = new vegFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(view == findViewById(R.id.orders)){
selectedFragment = new ordersFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(view == findViewById(R.id.you)){
selectedFragment = new youFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(view == findViewById(R.id.cart)){
Log.e("23","23");
selectedFragment = new cartFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
} else if(view == findViewById(R.id.selected)){
if(selectedText.getText().equals("Dairy")){
selectedFragment = new milkFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(selectedText.getText().equals("Meat")){
selectedFragment = new meatFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}else if(selectedText.getText().equals("Vegetable")){
selectedFragment = new vegFragment();
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment, selectedFragment);
fragmentTransaction.commit();
}
}
}
问题是这样,当当前打开的片段是Dairy时,购物车不可点击,而其余部分则不能。它进入handleChangeFragment(),但是在进入R.id.cart的过程中却以某种方式丢失了路径。如果有人有解决方案,那么请分享。 这是活动的快照。