如何实现以下方案以显示基于时间的POPUP对话框并附加到Listview

时间:2013-03-27 14:22:51

标签: android listview android-listview android-dialog

enter image description here

这是我实现的代码,用于显示弹出对话框

   public class ExPopup extends Activity {

Dialog myDialog;
Button myButton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    AlertDialog.Builder helpBuilder = new AlertDialog.Builder(ExPopup.this);
    helpBuilder.setTitle("Pop Up");
    helpBuilder.setMessage("This is a Simple Pop Up 1");
    helpBuilder.setPositiveButton("Accept",
            new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Do nothing but close the dialog
        }
    });

    helpBuilder.setNegativeButton("Decline", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });
    // Remember, create doesn't show the dialog
    final AlertDialog helpDialog = helpBuilder.create();
    WindowManager.LayoutParams wmlp = helpDialog.getWindow().getAttributes();
     wmlp.gravity = Gravity.TOP | Gravity.LEFT;
     wmlp.x = 70;   //x position
     wmlp.y = 70; 
    helpDialog.show();
    final Handler handler = new Handler();
    Timer tshow = new Timer();
    tshow.scheduleAtFixedRate(
            new TimerTask()
            {
                @Override
                public void run() {
                    handler.post(new Runnable() {
                        public void run() {
                            helpDialog.show();
                        }
                    });
                }
            },0,10000);
    final Handler handler1 = new Handler();
    Timer thide = new Timer();
    thide.scheduleAtFixedRate(
            new TimerTask()
            {
                @Override
                public void run() {
                    handler1.post(new Runnable() {
                        public void run() {
                            helpDialog.dismiss();
                        }
                    });
                }
            },0,20000);
    AlertDialog.Builder infoBuilder = new AlertDialog.Builder(ExPopup.this);
    infoBuilder.setTitle("Pop Up");
    infoBuilder.setMessage("This is a Simple Pop Up 2");
    infoBuilder.setPositiveButton("Accept",
            new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Do nothing but close the dialog
        }
    });

    infoBuilder.setNegativeButton("Decline", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });

    // Remember, create doesn't show the dialog
    final AlertDialog infoDialog = infoBuilder.create();
    WindowManager.LayoutParams wmlp1 = helpDialog.getWindow().getAttributes();
     wmlp1.gravity = Gravity.TOP | Gravity.LEFT;
     wmlp1.x = -75;   //x position
     wmlp1.y = -25; 
    helpDialog.show();
    infoDialog.show();
    final Handler handler11 = new Handler();
    Timer tshow1 = new Timer();
    tshow1.scheduleAtFixedRate(
            new TimerTask()
            {
                @Override
                public void run() {
                    handler11.post(new Runnable() {
                        public void run() {
                            infoDialog.show();
                        }
                    });
                }
            },0,10000);
    final Handler handler12 = new Handler();
    Timer thide1 = new Timer();
    thide1.scheduleAtFixedRate(
            new TimerTask()
            {
                @Override
                public void run() {
                    handler12.post(new Runnable() {
                        public void run() {
                            infoDialog.dismiss();
                        }
                    });
                }
            },0,20000);
            }

             }

从上面iam添加一个基于时间的弹出窗口,我的意思是每10秒添加一个新的弹出窗口,旧的弹出窗口将降低,所以2到3添加旧的弹出窗口必须从列表中消失....所以请在这种情况下帮助我谢谢你的帮助......

1 个答案:

答案 0 :(得分:0)

你走在正确的轨道上:

  1. 绘制线性或相对的四种布局。
  2. 将背景设置为透明
  3. 使popup2弹出4不可见。
  4. 每10分钟后调用一次线程,并将相对布局的线性设置为可见。
  5. 使用样式显示弹出窗口的动画。
  6. 运行,您将在每10秒钟后弹出一个