John Doee John Doee - 12 days ago 5
Android Question

cannot resolve symbol R Android DialogFragment

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..

Answer

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