Yesh Agnihotri Yesh Agnihotri - 1 month ago 17
Android Question

The app crashes as soon as i make my button clickable inside dialog fragment

Here is my code, If i remove the onclicklistener on button the app works just fine diaplaying the dailog i want to veiw.. but 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,
final Dialog dialog=getDialog();
dialog.setTitle("DialogFragment Tutorial");
Button button=(Button)dialog.findViewById(;
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
return rootView;


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

Then in code you should use

Button button=(Button)rootView.findViewById(;

rootView instead of dialog