凌云志轩
2015-05-11 10:48
采纳率: 89%
浏览 3.2k

android dialog一闪而过两下偶的钛合眼

我的dialog起来后我还没点按钮呢,自己就不见了,怎么回事。一闪而过,停留1S左右的样子

这是dialog所在的Demo(一个添加按钮的响应事件,点击添加按钮时先将该添加信息和已存数组中的逐个比较,如果有相同的就弹出dialog提示【带有确定和取消按钮】,如果添加成功了挑战到列表页)

 dev_reg_add.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String name = dev_selected.getSelectedItem().toString();
                    for (int i = 0; i <= dev_grp.dev_num; i++) {
                        if (name.equals(dev_grp.dev_list[i].dev_name)) {
                            Dialog dialog = new AlertDialog.Builder(AddDevActivity.this).setIcon(
                                    android.R.drawable.btn_star).setTitle("添加项已存在").setMessage(
                                    "你需要继续添加设备吗").setPositiveButton("是",
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {                                           Toast.makeText(AddDevActivity.this, "继续添加",
                                                    Toast.LENGTH_LONG).show();
                                        }
                                    }).setNeutralButton("否", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(AddDevActivity.this, "返回", Toast.LENGTH_LONG)
                                            .show();
                                }
                            }).create();

                            dialog.show();
                            name = null;
                            break;
                        }
                    }

                    dev_grp.dev_list[dev_grp.dev_num].dev_name = name;
                    dev_grp.dev_list[dev_grp.dev_num].dev_ip = "192.168.1.";
                    dev_grp.dev_num++;
                    Intent intent = new Intent(AddDevActivity.this, DevListActivity.class);
                    startActivity(intent);
                }
            });
            }

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • danielinbiti 2015-05-11 11:58
    已采纳
     dev_grp.dev_list[dev_grp.dev_num].dev_name = name;
                        dev_grp.dev_list[dev_grp.dev_num].dev_ip = "192.168.1.";
                        dev_grp.dev_num++;
                        Intent intent = new Intent(AddDevActivity.this, DevListActivity.class);
                        startActivity(intent);//这里切换了activity,当前打开的dialog就不见了。dialog是异步的,dialog.show()后会接着执行它后面的代码
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 凌云志轩 2015-05-12 01:22

    确定按钮事件

      dev_reg_add.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        String name = dev_selected.getSelectedItem().toString();
                        for (int i = 0; i <= dev_grp.dev_num; i++) {//创建的dev_grp类,用于保存数据
                            if (name.equals(dev_grp.dev_list[i].dev_name)) {想在此处添加dialog
                                name = null;
                                break;
                            }
                        }
                        isname(name);
                    }
                });
    

    public void isname(String name) {
    if(name.equals(null)){}
    else {

            dev_grp.dev_list[dev_grp.dev_num].dev_name = name;
            dev_grp.dev_list[dev_grp.dev_num].dev_ip = "192.168.1.";
            dev_grp.dev_num++;
            Intent intent = new Intent(AddDevActivity.this, DevListActivity.class);
            startActivity(intent);
        }
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题