I am working with DialogFragment to be able to show a dialog box where I request two data that are captured by two EditText, the progblem is when I want to recover what is written in those EditText, how can I recover the contents of those EditText:
This is my DialogFragment class:
public class Dialogo extends android.support.v4.app.DialogFragment {
private ArrayList<Registro_parqueo> lista;
private String archivo = "parquimetro.obj";
View view;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_signin, null))
// Add action buttons
.setPositiveButton("Registrar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
onClickGuardarPersona();
}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Dialogo.this.getDialog().cancel();
}
});
return builder.create();
}
public void onClickGuardarPersona() {
try{
EditText matricula = (EditText)getActivity().findViewById(R.id.parqueo);
EditText clientesillo = (EditText)getActivity().findViewById(R.id.cliente);
ObjectOutputStream objOutput = new ObjectOutputStream(getActivity().openFileOutput(archivo, MODE_PRIVATE));
objOutput.writeObject(new Registro_parqueo(matricula.getText().toString(),clientesillo.getText().toString()));
objOutput.close();
}catch (IOException e){
Toast.makeText(getActivity(), "Error al guardar el parqueo", Toast.LENGTH_SHORT).show();
}
}
}
And here is where I call the dialog box:
/**
* A simple {@link Fragment} subclass.
*/
public class listaparqueos extends Fragment {
public listaparqueos() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_listaparqueos, container, false);
//Button presiona =(Button)view.findViewById(R.id.buttonq);
FloatingActionButton crear = (FloatingActionButton)view.findViewById(R.id.flotador);
crear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickAlerta(v);
}
});
return view;
}
**public void onClickAlerta(View view){
//Dialogo.alerta(this,view).show();
Dialogo dialogo = new Dialogo();
dialogo.show(getFragmentManager().beginTransaction(), "confirmación");**
}
}
This is the dialog box where I want to retrieve the EditText: