Yesh Agnihotri Yesh Agnihotri - 1 year ago 76
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;

Answer Source

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

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