I have the problem that when creating all my fragments
the buttons of the activity
continue to work, that is, to be in one of the fragments
if I give somewhere on the screen where there is a button in the activity
this is pressed.
the java file of the fragment I leave empty and I do everything from the activity
, can that be the reason?
public class LogoutFragment extends Fragment {
public LogoutFragment() { }
final View vista = inflater.inflate( R.layout.fragment_logout, container, false );
logoutNo = vista.findViewById( R.id.imageButton3 );
logoutYes = vista.findViewById( R.id.imageButton2 );
logoutYes.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
//FirebaseAuth.getInstance().signOut();
// auth.signOut();
AuthUI.getInstance()
.signOut( getActivity() )
.addOnCompleteListener( new OnCompleteListener<Void>() {
public void onComplete(@NonNull Task<Void> task) {
// ...
}
} );
Toast.makeText( getActivity(), "Te has deslogueado", Toast.LENGTH_SHORT ).show();
Intent intent = new Intent(getActivity(), MainActivity.class);
getActivity().startActivity(intent);
}
} );
logoutNo.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
getFragmentManager().beginTransaction().
remove( getFragmentManager().findFragmentById( R.id.contenedor ) ).commit(); // codigo para salir del fragment hacia la activity
}
} );
return vista;
in the main to choose the fragments I have this, I do not know if it can come around
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
FragmentManager fragmentManager = getFragmentManager();
if (id == R.id.nav_camera) {
Toast.makeText( context, R.string.very_soon, Toast.LENGTH_SHORT ).show();
} else if (id == R.id.nav_gallery) {
fragmentManager.beginTransaction().replace( R.id.contenedor, new GalleryFragment() ).commitAllowingStateLoss();
} else if (id == R.id.nav_slideshow) {
Toast.makeText( context, R.string.very_soon, Toast.LENGTH_SHORT ).show();
} else if (id == R.id.nav_logout) {
fragmentManager.beginTransaction().replace( R.id.contenedor, new LogoutFragment() ).commitAllowingStateLoss();
}
DrawerLayout drawer = findViewById( R.id.drawer_layout );
drawer.closeDrawer( GravityCompat.START );
return true;
}