-2

Here is my code, if I remove the onclicklistener on button the app works just fine displaying the dialog I want to view. However as soon I make it clickable the app stops working.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.dialogf, container,
            false);
    final Dialog dialog=getDialog();
    dialog.setTitle("DialogFragment Tutorial");
    Button button=(Button)dialog.findViewById(R.id.ok1);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           dialog.dismiss();
        }
    });
    return rootView;
}
Yash
  • 61
  • 5

1 Answers1

1

if this R.id.ok1 is in your layout R.layout.dialogf file.

Then in code you should use

Button button=(Button)rootView.findViewById(R.id.ok1);

rootView instead of dialog

AJay
  • 1,233
  • 10
  • 19