I'm creating a project that needs to create users, I have a ready method, however I'm trying to put a way to display in a dialog.
I created a screen with a recycler view to display the list of users, and when clicking on the add button it calls this dialog with the fields, and when you click on add in dialog it inserts the values in the database. however the logs does not point to any errors, but nothing happens, and the method I implemented is based on what I put together in a separate view.
public class Admin_Usuarios extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_usuarios);
EntradaApp.setContext(getApplicationContext());
}// fim oncreate
public void adicionarUsuarios(View view){
CadastroUsuario_dialog.show(getSupportFragmentManager());
}
}
This is the class that calls the dialog
public class CadastroUsuario_dialog extends DialogFragment{
private static final String PREF_NAME = "Adicionar_UsuarioPreferences";
String tipo;
String senha;
String nome;
String usuario;
String email;
String id_tipo;
Button btcriar;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout.dialog_adicionar_usuario, null);
ArrayAdapter adapter = new ArrayAdapter(getActivity() ,android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
List<String> tipos = new ArrayList<String>();
tipos.add("Administração");
tipos.add("Comum");
Spinner spin1 = (Spinner) view.findViewById(R.id.sptipo_usuario);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, tipos);
ArrayAdapter<String> spinnerArrayAdapter = arrayAdapter;
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spin1.setAdapter(spinnerArrayAdapter);
spin1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int posicao, long id) {
//pega nome pela posição
tipo = parent.getItemAtPosition(posicao).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return new AlertDialog.Builder(getActivity()).setView(view).create();
}
public static void show(FragmentManager fragmentManager) {
android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction();
Fragment prev = fragmentManager.findFragmentByTag("editar_carro");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
CadastroUsuario_dialog frag = new CadastroUsuario_dialog();
Bundle args = new Bundle();
frag.show(ft, "Ajuda");
}
}
this is the implemented dialog
public void adicionarusuario(View view ) {
EditText etid_tipo = (EditText) view.findViewById(R.id.etid1);
EditText etnome = (EditText) view.findViewById(R.id.etnome1);
EditText etusuario = (EditText) view.findViewById(R.id.etusuario1);
EditText etsenha = (EditText) view.findViewById(R.id.etsenha1);
EditText etemail = (EditText) view.findViewById(R.id.etemail1);
nome = etnome.getText().toString();
email = etemail.getText().toString();
usuario = etusuario.getText().toString();
senha = etsenha.getText().toString();
id_tipo = etid_tipo.getText().toString();
Usuarios_Model u = new Usuarios_Model();
u.setNome(nome);
u.setEmail(email);
u.setSenha(senha);
u.setUsuario(usuario);
u.setTipo_usuario(tipo);
u.setId(Integer.parseInt(id_tipo));
List<Usuarios_Model> ls = new ArrayList<>();
ls.add(u);
new DAO_usuario().Insert(ls);
}
System DAO
public class DAO_usuario extends DAO_Principal<Usuarios_Model> {
@Override
protected ContentValues getContentValues(Usuarios_Model object) {
ContentValues contentValues = new ContentValues();
contentValues.put(("id"), object.getId());
contentValues.put(("nome"), object.getNome());
contentValues.put(("usuario"), object.getUsuario());
contentValues.put(("senha"), object.getSenha());
contentValues.put(("email"), object.getEmail());
contentValues.put(("tipo_usuario"), object.getTipo_usuario());
return contentValues;
}
@Override
protected Usuarios_Model FillObject(Cursor cursor) {
Usuarios_Model usuarios_model = new Usuarios_Model();
usuarios_model.setId(cursor.getInt(cursor.getColumnIndex("id")));
usuarios_model.setNome(cursor.getString(cursor.getColumnIndex("nome")));
usuarios_model.setUsuario(cursor.getString(cursor.getColumnIndex("usuario")));
usuarios_model.setSenha(cursor.getString(cursor.getColumnIndex("senha")));
usuarios_model.setEmail(cursor.getString(cursor.getColumnIndex("email")));
usuarios_model.setTipo_usuario(cursor.getString(cursor.getColumnIndex("tipo_usuario")));
return null;
}
@Override
protected String getTable() {
return "Usuario";
}
@Override
public void Insert(List<Usuarios_Model> list) {
super.Insert(list);
}
@Override
public void Erase(){
super.Erase();
}
public void Erase(int id, String condicao) {
super.Erase(id, condicao);
}
@Override
public List<Usuarios_Model> ListAll() {
return super.ListAll();
}
In a view the part works, however when placing in the dialog happens some error and I'm not finding. Thank you!