lagfvu lagfvu - 2 months ago 4
Android Question

I have this form in a dialog box, but i cannot get the values of the input boxes

I have a dialog box with a form, the user enters some data and i want to get that data but when i log the data to view it i am getting nothing.

public Dialog onCreateDialog (Bundle savedInstanceState)
{

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();

final View view = inflater.inflate(R.layout.incident_form,null);


builder.setView(inflater.inflate(R.layout.incident_form,null)
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id)
{
title = (EditText) view.findViewById(R.id.report_title);
recom = (EditText) view.findViewById(R.id.report_recommendation);
content = (EditText) view.findViewById(R.id.report_content);

titleString = title.getText().toString();
recomString = recom.getText().toString();
contentString = content.getText().toString();

submitForm(titleString,recomString,contentString);
dialog.cancel();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}

Answer

You have included the layout twice in you dialog please check. Either setview(View) you should use because view you have already initialized on the top like this

    final View view = inflater.inflate(R.layout.incident_form,null);

or intialize it in you setView() method like you are doing below

setView(inflater.inflate(R.layout.incident_form,null)

. You are adding it twice that is why this is happening.

Glad to help you...