package forrest.cartoon.dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
public abstract class ViewOrMegDialog extends Builder {
public ViewOrMegDialog(Context ctx, String title, int resource) {
super(ctx);
this.setTitle(title);
this.setView(LayoutInflater.from(ctx).inflate(resource, null));
setPositive();
setNegative();
}
public ViewOrMegDialog(Context ctx, String title, String meg){
super(ctx);
this.setTitle(title);
this.setMessage(meg);
setPositive();
setNegative();
}
private void setPositive() {
this.setPositiveButton("确定", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
doPositive();
}
});
}
private void setNegative() {
this.setNegativeButton("取消", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}
protected abstract void doPositive();
}
package forrest.cartoon.dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
public abstract class ItemsDialog extends Builder {
public ItemsDialog(Context ctx, String title,String[] items){
super(ctx);
this.setTitle(title);
this.setItems(items, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
doItems(which);
}
});
setNegative();
}
private void setNegative() {
this.setNegativeButton("取消", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}
protected abstract void doItems(int which);
}