-2

I would like create an AlertDialog with a custom XML layout, but in my class I can't found R variable, why ?

This is my class :

public class NewTestDialogFragment extends DialogFragment {

    public NewTestDialogFragment(){
        super();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        builder.setView(inflater.inflate(R.layout.name_dialog, null));

        builder.setTitle("Test");

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dismiss();
            }
        });

        return builder.create();
    }
}

R is not found. If I import R, the application crash..

Jaap
  • 71,900
  • 30
  • 164
  • 175
John Doee
  • 49
  • 1
  • 7

1 Answers1

1

You may have changed your application package name in manifest file. Check it then import, clean and then build.

atifali
  • 174
  • 15