0
Good afternoon, I have a Fragment that has the following XML
<Button
android:id="@+id/salvar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/gradiente_azul_semconor"
android:text="Salvar"
android:textColor="@color/cinza"
android:onClick="salvarUsuario"
android:layout_below="@+id/relativeLayout" />
But I cannot select in onclick the save functionUsuario that is in the class of that fragment, only the functions that are in the parent Activity.
That would be the function:
public void salvarUsuario(View view){
EditText nomeEt = (EditText) getActivity().findViewById(nome);
EditText emailEt = (EditText) getActivity().findViewById(email);
EditText npEt = (EditText) getActivity().findViewById(np);
Spinner tipoFuncSp = (Spinner) getActivity().findViewById(tipoFunc);
Button salvarBt = (Button) getActivity().findViewById(salvar);
usuario.setNome(nomeEt.getText().toString());
usuario.setEmail(emailEt.getText().toString());
usuario.setTipoFunc(tipoFuncSp.toString());
usuario.setNp(npEt.getText().toString());
db_funcao bd = new db_funcao(getContext());
bd.inserir(usuario);
Toast.makeText(getActivity(), "Usuário inserido com sucesso!", Toast.LENGTH_SHORT).show();
}
How do I call a function that is in the Fragment class itself and not in the main Activity.
thank you.