Use Below code:
mBtnNext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (validationSuccess()) {
Intent mIntent = new Intent(
YourActivity.this,
NewActivity.class);
} else {
AlertDialog();
}
});
private Boolean validationSuccess(){
if(editUsername.getText().toString().equalsIgnoreCase("")){
Toast.makeText(getApplicationContext();"Please enter name",0).show();
return false;
}
if(radioGroupDesignation.getCheckedRadioButtonId()<=0){
Toast.makeText(getApplicationContext();"Please select designation",0).show();
return false;
}
if(radioGroupExp.getCheckedRadioButtonId()<=0){
Toast.makeText(getApplicationContext();"Please select Experience",0).show();
return false;
}
if(spinner.getSelectedItemPosition()==0){
Toast.makeText(getApplicationContext();"Please select Depatrment",0).show();
return false;
}
return true;
}