This is the activity code. I'm tryin to go to the fragment when I click on a button. But I don't know how to do it. And when I use intent like the intent report, it asked me to declare the shopping_cart (fragment) at manifest.
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case (R.id.shopping_cart):
case (R.id.report):
Intent report;
report = new Intent(getApplicationContext(), Report.class);
startActivity(report);
break;
}
return super.onOptionsItemSelected(item);
}
Just Do This For Going Activity To Fragment
public void replace(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame, fragment);
fragmentTransaction.addToBackStack(fragment.toString());
fragmentTransaction.commit();
}
And In Button Click Just Put Below Code
replace(new FragmentName());