show Alert Window With Delete On Right - Android User Interface

Android examples for User Interface:Alert Dialog

Description

show Alert Window With Delete On Right

Demo Code


import java.util.Calendar;
import java.util.List;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TimePicker;
import android.widget.Toast;

public class Main{
    /** mAlertWindow */
    private static AlertWindow mAlertWindow;
    public static AlertWindow showAlertWindowWithDeleteOnRight(
            Context context, CharSequence title, CharSequence message,
            CharSequence positiveText,
            final AlertWindow.OnClickListener positiveListener,
            CharSequence negativeText,
            final AlertWindow.OnClickListener negativeListener) {

        int style = 0;
        if (title != null) {
            style |= AlertWindow.HAS_TITLE;
        }/*from   w ww. j  a va  2  s  .c o  m*/
        if (positiveText != null) {
            style |= AlertWindow.HAS_OK;
        }
        if (negativeText != null) {
            style |= AlertWindow.HAS_CANCEL;
        }
        style |= AlertWindow.HAS_DELETEONRIGHT;
        return getAlertWindow(context, style, title, message, positiveText,
                positiveListener, negativeText, negativeListener);
    }
    private static AlertWindow getAlertWindow(Context context, int style,
            CharSequence title, CharSequence message,
            CharSequence positiveText,
            final AlertWindow.OnClickListener positiveListener,
            CharSequence negativeText,
            final AlertWindow.OnClickListener negativeListener) {

        AlertWindow aw = new AlertWindow(context, style);
        mAlertWindow = aw;
        aw.setTitle(title);
        aw.setMessage(message);

        if (positiveText != null) {
            aw.setPositiveButton(positiveText,
                    new AlertWindow.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            if (positiveListener != null) {
                                positiveListener.onClick(dialog, which);
                            } else {
                                dialog.dismiss();
                            }
                        }
                    });
        }
        if (negativeText != null) {
            aw.setNegativeButton(negativeText,
                    new AlertWindow.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            if (negativeListener != null) {
                                negativeListener.onClick(dialog, which);
                            } else {
                                dialog.dismiss();
                            }
                        }
                    });
        }
        aw.show();

        return aw;
    }
}

Related Tutorials