Add Toast on button Click in Android

Import

import android.widget.Toast;

Add onClickListner

Button btn1 = (Button) findViewById(R.id.btnopt1_a);
btn1.setOnClickListener(new OnClickListener() { 
    public void onClick(View v)  {
        Toast.makeText(getBaseContext(), "Your answer is correct!" , Toast.LENGTH_SHORT ).show();   
    }
});

Leave a Reply

Your email address will not be published. Required fields are marked *