OnClickListener btn2_events = new OnClickListener() {
            @Override
            public void onClick(View v)
            {
                //Here you must use "MainActivity.this" for the parameter Context.
                //You can not use "getApplicationContext()" any more!
                Dialog dlg = new AlertDialog.Builder(MainActivity.this)
                                .setTitle("A question")
                                .setMessage("How many people are there in your home?")
                                .setPositiveButton("Four", null)
                                .setNegativeButton("Three", null)
                                .create();
                dlg.show();
            }
        };
        findViewById(R.id.button2).setOnClickListener(btn2_events);
      

