Diaglog弹出框

先给一个数组:String[] items = new String[]{"全部", "热门动态", "旅游景点", "美食推荐", "酒店住宿",
            "本地特产", "农家玩乐", "娱乐中心", "美容美发"};
            private String[] food = new String[]{"特色餐饮", "中西餐厅", "奶茶店", "小吃店"};
    private String[] xiuxian = new String[]{"休闲会所", "休闲茶楼"};
    private String[] meirong = new String[]{"美容院", "发型屋"};
            首先创建一个AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
            遍历出数组的元素:for (int i = 0; i < items.length; i++) {
                    if (searchall.getText().toString().equals(items[i])) {
                        location = i;
                    }
                    通过dialog中的一个方法:
                      builder.setSingleChoiceItems(items, location, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        searchall.setText(items[which]);
//判断是否有两个选项
                        switch (which) {
                        //执行到这几种情况时显示第二个弹框
                            case 3:
                                search_img2.setVisibility(View.VISIBLE);
                                searchall2.setVisibility(View.VISIBLE);
                                searchall2.setText(food[0]);
                                break;
                            case 7:
                                search_img2.setVisibility(View.VISIBLE);
                                searchall2.setVisibility(View.VISIBLE);
                                searchall2.setText(xiuxian[0]);
                                break;
                            case 8:
                                search_img2.setVisibility(View.VISIBLE);
                                searchall2.setVisibility(View.VISIBLE);
                                searchall2.setText(meirong[0]);
                                break;
                            default:
                                search_img2.setVisibility(View.GONE);
                                searchall2.setVisibility(View.GONE);
                                editext.setText(items[which]);
                                break;
                        }
                        dialog.dismiss();
                        secondDialog(which);
                    }
                });
                builder.create().show();
//调用第二次弹框
 private void secondDialog(final int position) {

        searchall2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position) {
                    case 3:
                        showD(food);
                        break;
                    case 7:
                        showD(xiuxian);
                        break;
                    case 8:
                        showD(meirong);
                        break;
                }
            }
        });

    }
   //第二次弹框
     private void showD(final String[] food) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        for (int i = 0; i < food.length; i++) {
            if (searchall2.getText().toString().equals(food[i])) {
                location = i;
            }
        }
        builder.setSingleChoiceItems(food, location, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                searchall2.setText(food[which]);
                editext.setText(food[which]);
                dialog.dismiss();
            }


        });
        builder.create().show();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值