一个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. [Luogu1343]地震逃生 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...

  2. DVWA之文件包含(File inclusion)

    daFile inclusion的意思就是文件包含,当服务器开启了allow_url_include选项时,就可以通过PHP的某些特征函数 include,require和include_once,r ...

  3. 最小化安装centos后ifconfig看不到eth0

    最小换安装centos后,ifconfig看不到eth0,只看到一个lo ifup eth0

  4. HTML5文档结构 摘要

    <!DOCType html>--声明文档结构类型 <html lang=zh-cn> <head> <meta charset=utf-8> < ...

  5. vijos 1164 曹冲养猪

    描述 自从曹冲搞定了大象以后,曹操就开始捉摸让儿子干些事业,于是派他到中原养猪场养猪,可是曹冲满不高兴,于是在工作中马马虎虎,有一次曹操想知道母猪的数量,于是曹冲想狠狠耍曹操一把.举个例子,假如有16 ...

  6. 洛谷 P1744 采购特价商品

    题目背景 <爱与愁的故事第三弹·shopping>第一章. 题目描述 中山路店山店海,成了购物狂爱与愁大神的“不归之路”.中山路上有n(n<=100)家店,每家店的坐标均在-1000 ...

  7. Cannot fetch index base URL https://pypi.python.org/pypi/ 解决方法

    vi /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # ...

  8. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  9. block总结我的

    1) struct Block_descriptor { unsigned long int reserved; unsigned long int size; void (*copy)(void * ...

  10. @ConditionalOnProperty来控制Configuration是否生效

    1. 简介 Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效 2. 说明 @Retention(RetentionPolicy.RUNTI ...