0
I have a CRUD to add users but I’m having trouble implementing the edit. User clicking edit wanted edittext to be loaded already filled.
For that, I tried to implement something like:
ImageView editarBt = (ImageView) view.findViewById(R.id.editar);
editarBt.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View view) {
Bundle data = new Bundle();
data.putString("nome", listaUser.get(auxPosition).getNome());
data.putString("email", listaUser.get(auxPosition).getEmail());
data.putString("np", listaUser.get(auxPosition).getNp());
data.putString("tipoFunc", listaUser.get(auxPosition).getTipoFunc());
data.putInt("id", listaUser.get(auxPosition).getId());
Fragment fragment = new adicionar_usuario();
fragment.setArguments(data);
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.content,fragment, fragment.getTag()).addToBackStack(null).commit();
}
});
That is, when the user click on the icon to edit, I wanted the screen already came with the information loaded to give the update.
I got this from the Internet:
Intent intent = new Intent(getActivity(), adicionar_usuario.class);
manager.putFragment(bundle,"nome", listaUser.get(auxPosition).getNome());
intent.putExtra("email", listaUser.get(auxPosition).getEmail());
intent.putExtra("np", listaUser.get(auxPosition).getNp());
intent.putExtra("tipoFunc", listaUser.get(auxPosition).getTipoFunc());
intent.putExtra("id", listaUser.get(auxPosition).getId());
getContext().startActivity(intent);
But since it is a Fragment, the Intent does not become viable.
And in my file I want the information to be loaded (add user), with the Intent is:
Intent intent = getActivity().getIntent();
if(intent != null){
Bundle bundle = intent.getExtras();
if(bundle != null){
usuario.setId(bundle.getInt("id"));
usuario.setNome(bundle.getString("nome"));
usuario.setEmail(bundle.getString("email"));
usuario.setTipoFunc(bundle.getString("tipoFunc"));
usuario.setNp(bundle.getString("np"));
nomeEt.setText(usuario.getNome());
emailEt.setText(usuario.getEmail());
npEt.setText(usuario.getNp());
tipoFuncSp.toString();
// senhaEt.setVisibility(View.GONE);
salvarBt.setVisibility(View.GONE);
editarUserBt.setVisibility(View.VISIBLE);
}
}
Someone can help me?
Maybe this link can help you. https://stackoverflow.com/questions/16036572/how-to-pass-values-between-fragments
– Victor Tripeno