lagfvu lagfvu - 1 year ago 61
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);

.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
title = (EditText) view.findViewById(;
recom = (EditText) view.findViewById(;
content = (EditText) view.findViewById(;

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

.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
public void onClick(DialogInterface dialog, int id) {
return builder.create();

Answer Source

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


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

Glad to help you...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download