show Alert Window With Menu - Android User Interface

Android examples for User Interface:Menu

Description

show Alert Window With Menu

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 void showAlertWindowWithMenu(Context context,
            List<String> lstStr,
            AlertWindow.OnListItemClickListener listener) {
        int style = AlertWindow.HAS_MENU;
        AlertWindow aw = new AlertWindow(context, style, lstStr);
        mAlertWindow = aw;//w  w w  .j  a  va2s.  c o  m
        aw.setItemClickListener(listener);
        aw.show();
    }
    public static void showAlertWindowWithMenu(Context context,
            List<String> lstStr, int offsetX, int offsetY,
            AlertWindow.OnListItemClickListener listener) {
        int style = AlertWindow.HAS_MENU;
        AlertWindow aw = new AlertWindow(context, style,
                R.style.no_dim_dialog, lstStr);
        mAlertWindow = aw;
        aw.setItemClickListener(listener);
        WindowManager.LayoutParams lp = aw.getWindow().getAttributes();
        lp.gravity = Gravity.LEFT | Gravity.TOP;
        lp.x = offsetX;
        lp.y = offsetY;

        aw.show();
    }
}

Related Tutorials