1
I have a class like Fragment
and would like when the user clicks the button to go to another screen that is Fragment.. how can I do this?
public class AlertaFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_alerta, container, false);
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
return view;
}
}
@EDIT
I put it like this: It highlights the argument in red...
final FragmentTransaction ft = getFragmentManager().beginTransaction();
CadastroAlertaFragment cadastro = new CadastroAlertaFragment();
ft.replace(R.id.cadastro_frag, cadastro, cadastro.getTag());
ft.commit();
Error:
Error:(167, 48) error: incompatible types: CadastroAlertaFragment cannot be converted to Fragment
The new fragment will take the same place as the current fragment?
– Reginaldo Rigo
Not.............
– Aline
How is your class
CadastroAlertaFragment
?– rsicarelli
public class Cadastre alertafragment extends Fragment {}
– Aline
and has a registration layout for it called fragment_cadastro_alerta.xml and put an id in the android layout:id="@+id/cadastro_frag"
– Aline