一个button的:

package jp.co.hyakujushibank.view

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import jp.co.hyakujushibank.securestarter.R @Suppress("DEPRECATION")
/**
*
* Created by liuhaolong on 2017/07/05.
*/
class AlertDialog : Dialog {
private var supContext: Context? = null
private var dialogMsg: String? = ""
private var buttonText: String? = "閉じる"
private var imageRes: Int = 0
private var titleFlag: Boolean = false constructor(supContext: Context, dialogMsg: String) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.buttonText = buttonText
} constructor(supContext: Context, dialogMsg: String, buttonText: String) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.buttonText = buttonText
} constructor(supContext: Context, dialogMsg: String, buttonText: String, imageRes: Int) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.buttonText = buttonText
this.imageRes = imageRes
} constructor(supContext: Context, dialogMsg: String, buttonText: String, imageRes: Int, titleFlag: Boolean) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.buttonText = buttonText
this.imageRes = imageRes
this.titleFlag = titleFlag
} //クリックリスナーインターフェース
var clickListenerInterface: ClickListenerInterface? = null interface ClickListenerInterface {
//確認
fun doConfirm()
} override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
//初期化
init() } fun setClicklistener(clickListenerInterface: ClickListenerInterface) {
//クリックリスナーインターフェース
this.clickListenerInterface = clickListenerInterface
} fun init() {
//充填画面
val inflater = LayoutInflater.from(supContext)
val view = inflater.inflate(R.layout.alert_dialog, null)
setContentView(view)
//メッセージ
val msgTitleText = view.findViewById(R.id.msg_title_text) as TextView
if (titleFlag) {
msgTitleText.visibility = View.VISIBLE
}
//メッセージ
val msgText = view.findViewById(R.id.confirm_msg_text) as TextView
//確認
val clickBtn = view.findViewById(R.id.click_btn) as Button
//画像
val dialogImage = view.findViewById(R.id.dialog_image) as ImageView
if (imageRes == 0) {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(R.mipmap.ic_error))
} else {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(imageRes))
}
//メッセージ
msgText.text = dialogMsg
//確認
clickBtn.text = buttonText
//許可キャンセル
setCancelable(false)
setCanceledOnTouchOutside(false)
//確認
clickBtn.setOnClickListener(clickListener()) val dialogWindow = window
val lp = dialogWindow.attributes
val d = context.resources.displayMetrics
lp.width = (d.widthPixels * 0.95).toInt()
dialogWindow.attributes = lp
} inner class clickListener : View.OnClickListener {
override fun onClick(v: View) {
val id = v.id
when (id) {
//ボタン
R.id.click_btn -> clickListenerInterface!!.doConfirm()
}
}
}
} 如何用:
val alert = AlertDialog(activity, resposeAllTransaction.resultData!!.error_messege!!)
alert.setClicklistener(object : AlertDialog.ClickListenerInterface {
override fun doConfirm() {
alert.dismiss()
}
})
alert.show()
alertAgree = AlertDialog(this@RulesActivity, "利用規定に同意してからお進みください", "閉じる")
alertAgree!!.setClicklistener(object : AlertDialog.ClickListenerInterface {
override fun doConfirm() {
closeAlertAgree()
}
})

val alert = AlertDialog(this@CheckPassCodeActivity, "パスコードを5回間違えたので、ログアウトします。", "閉じる", R.mipmap.ic_error)
alert.setClicklistener(object : AlertDialog.ClickListenerInterface {
override fun doConfirm() {
Api.logoutForPasscodeApi(this@CheckPassCodeActivity)
alert.dismiss()
}
})
alert.show()

val alert = AlertDialog(context, msg, "閉じる", R.mipmap.info, true)
alert.setClicklistener(object : AlertDialog.ClickListenerInterface {
override fun doConfirm() {
alert.dismiss()
}
})


Dialog共通写法(一个button)的更多相关文章

  1. Dialog共通写法(两个button)

    package jp.co.hyakujushibank.view import android.app.Dialogimport android.content.Contextimport andr ...

  2. Title共通写法

    用: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_c ...

  3. 2016.8.19 在dialog上增加一个button出现错误:failed to execute setAttribute on Element...

    目标:想要在dialog上多加一个button. 语法来自: http://api.jqueryui.com/dialog/#option-buttons   可见新增在dialog上的button要 ...

  4. 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)

    http://www.cnblogs.com/xqin/archive/2013/06/06/3120887.html 前言 我写代码喜欢提取一些共通的东西出来,之前的一篇博客中说了如何用一个共通的v ...

  5. 一个共通的viewModel搞定所有的分页查询一览及数据导出(easyui + knockoutjs + mvc4.0)

    前言 大家看标题就明白了我想写什么了,在做企业信息化系统中可能大家写的最多的一种页面就是查询页面了.其实每个查询页面,除了条件不太一样,数据不太一样,其它的其实都差不多.所以我就想提取一些共通的东西出 ...

  6. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  7. rails跑通第一个demo

    rails -h 查看帮助 Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby bina ...

  8. 共通css初次尝试

    1.网页的主要的html <@fn.html css=["${basePath}/css/help/guideCommon.css${versionControl}"]tit ...

  9. iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)

    //直接代码 只包含 折叠展开字典的处理搭建#import "CFViewController.h" @interface CFViewController ()<UITab ...

随机推荐

  1. CF1093D Beautiful Graph

    思路: 题目倒是没啥好说的,就是注意memset的效率问题.如果循环多次调用memset去初始化一个比较大的数组,那就会很费时间.就是因为这个被hack了.:( 实现: #include <bi ...

  2. 20170308web作业1

    代码20170308001: <%@ page language="java" import="java.util.*" pageEncoding=&qu ...

  3. 进程间通信,把字符串指针作为参数通过SendMessage传递给另一个进程,不起作用

    参数发送进程: CString csCmd=AfxGetApp()->m_lpCmdLine; if (!csCmd.IsEmpty()) { pWndPrev->SendMessage( ...

  4. hdu 1181 深搜

    中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool ...

  5. 树形dp——覆盖所有边的最少费用(Protecting Zonk)

    一.问题描述 有一个n(n<=10000)个节点的无根树.有两种装置A,B,每种都有无限多个. 1.在某个节点X使用A装置需要C1(C1<=1000)的花费,并且此时与节点X相连的边都被覆 ...

  6. 【工具篇】在.Net中实现HTML生成图片或PDF的几种方式

    前段时间由于项目上的需求,要在.Net平台下实现把HTML内容生成图片或PDF文件的功能,特意在网上研究了几种方案,这里记录一下以备日后再次使用.当时想着找一种开发部署都比较清爽并且运行稳定的方案,但 ...

  7. Linux平台搭建roboframework

    安装步骤介绍: . 在Centos7..1503下,默认的python的版本2./site-packages/). 2.安装pip 第一步: ()下载setuptools包 # wget http:/ ...

  8. EXTJS中文乱码

    在<head>中加入 <meta http-equiv="Content-Type" content="text/html; charset=GB231 ...

  9. Leetcode 7 反转整数Reverse Integer

    给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: ...

  10. (40)zabbix监控web服务器访问性能

    zabbix web监控介绍 在host列可以看到web(0),在以前的版本这项是独立出来的,这个主要实现zabbix对web性能的监控,通过它可以了解web站点的可用性以及性能. 最终将各项指标绘制 ...