android 您所在的位置:网站首页 对话框怎么关闭 android

android

2024-06-17 04:52| 来源: 网络整理| 查看: 265

android-如何关闭AlertDialog.Builder对话框

前言 在实际写代码的时候,AlertDialog.Builder的使用算是比较频繁的,在对AlertDialog.Builder关闭的时候,我们会发现,AlertDialog.Builder对话框没有相对应的finish()或者dismiss()这样的方法可使用。

那么我们在关闭的时候怎么才能做到呢?

##AlertDialog 父类AlertDialog有dismiss方法,可以实现对话框的关闭,而且AlertDialog.Builder在.show()的时候会得到一个AlertDialog对象,用dismiss方法将该Builder关闭。

##自定义的AlertDialog.Builder布局示例 这里写图片描述

/** * 设置dialog的出现 * @param hangTag */ private void showCustomizeDialog(HangTag hangTag) { final AlertDialog.Builder customizeDialog = new AlertDialog.Builder(getActivity()); customizeDialog.setCancelable(false); View infoview = LayoutInflater.from(getActivity()).inflate(R.layout.wr_dialog_hangtag_info, null, false); TextView exchangeName, volume, marketPirce, region, irrigation, administrative, watertype,exchangeTime; Button backColse; exchangeTime = (TextView) infoview.findViewById(R.id.exchange_time); exchangeName = (TextView) infoview.findViewById(R.id.exchangeName); volume = (TextView) infoview.findViewById(R.id.volume); marketPirce = (TextView) infoview.findViewById(R.id.marketPirce); region = (TextView) infoview.findViewById(R.id.region); irrigation = (TextView) infoview.findViewById(R.id.irrigation); administrative = (TextView) infoview.findViewById(R.id.administrative); watertype = (TextView) infoview.findViewById(R.id.watertype); backColse = (Button) infoview.findViewById(R.id.back_colse); exchangeTime.setText(hangTag.getGprq()+""); exchangeName.setText(hangTag.getName()); volume.setText(hangTag.getSl() + ""); marketPirce.setText(hangTag.getJg() + ""); region.setText(hangTag.getSzdq()); irrigation.setText(hangTag.getSzgq()); administrative.setText(hangTag.getSzglq()); if (hangTag.getWaterType() == 8101) { watertype.setText("地下水"); } else if (hangTag.getWaterType() == 8100) { watertype.setText("地表水"); } customizeDialog.setView(infoview); final AlertDialog dialog = customizeDialog.show(); /** * 返回 */ backColse.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); }

以上就是全部内容,仅做笔记,不喜勿喷!

在这里插入图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有