Copyright (c) 2014, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are m...
If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.livio.sdl.dialogs;
/*fromwww.java2s.com*/import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import com.livio.sdl.R;
/**
* An abstract class that represents a dialog with an OK button and a cancel button. Subclasses
* can extend this class to create different types of OK/Cancel dialogs. Subclasses
* must set positive / negative buttons in their constructor and call createDialog() as the last
* line of the constructor.
*
* @author Mike Burke
*
*/publicabstractclass BaseOkCancelDialog extends BaseAlertDialog {
protected DialogInterface.OnClickListener okButton, cancelButton;
public BaseOkCancelDialog(Context context, String title, int resource) {
super(context, title, resource);
}
@Override
protectedvoid createDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title)
.setView(view)
.setPositiveButton(context.getResources().getString(R.string.positive_button), okButton)
.setNegativeButton(context.getResources().getString(R.string.negative_button), cancelButton)
.setCancelable(cancelable);
dialog = builder.create();
}
/**
* Sets the positive button click listener for the dialog.
*
* @param okButton The button click listener for the positive button
*/protectedvoid setPositiveButton(DialogInterface.OnClickListener okButton){
this.okButton = okButton;
if(dialog != null){
dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.positive_button), okButton);
}
}
/**
* Sets the negative button click listener for the dialog.
*
* @param cancelButton The button click listener for the negative button
*/protectedvoid setNegativeButton(DialogInterface.OnClickListener cancelButton){
this.cancelButton = cancelButton;
if(dialog != null){
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.negative_button), cancelButton);
}
}
}