一个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. GetDC(),ReleaseDC()

    用GetDC()得到的DC, 必须调用ReleaseDC()用CreateDC()创建的DC, 必须调用DeleteDC() 两者是不能混淆的.一种典型的错误代码如下:CDC* pDC = GetDC ...

  2. NSString+TimeCategory

    NSString+TimeCategory.h //------------------------------------------------ #import <foundation fo ...

  3. UISearchBar clearButton

    When the searchBar:textDidChange: method of the UISearchBarDelegate gets called because of the user ...

  4. 什么是Java Marker Interface(标记接口)

    先看看什么是标记接口?标记接口有时也叫标签接口(Tag interface),即接口不包含任何方法.在Java里很容易找到标记接口的例子,比如JDK里的Serializable接口就是一个标记接口. ...

  5. eclipse 的project explorer问题,这个怎样把localFileSystem去掉,

    这个非常简单 把勾去掉就可以了

  6. HDU 6052 To my boyfriend(容斥+单调栈)

    题意:对于一个n*m的方格,每个格子中都包含一种颜色,求出任意一个矩形包含不同颜色的期望. 思路: 啊啊啊啊啊,补了两天,总算A了这道题了,简直石乐志,前面的容斥还比较好写,后面的那个>13那个 ...

  7. 屏蔽系统的Ctrl+c/x/v操作

    实现效果: 知识运用: KeyEventArgs类的Control, public bool Control {get;} //获取一个值 该值指示是否曾按下Ctrl键 KeyCode和Handled ...

  8. gitlab autuo devops

    [参考文章] Chengzi_comm的专栏 use gitlab ci docker run gitlab-runner gitlab-runner register 1. 在虚拟机或服务器运行gi ...

  9. oracle中group by的高级用法

    简单的group by用法 select c1,sum(c2) from t1 where t1<>'test' group by c1 having sum(c2)>100; ro ...

  10. Java第十二次作业:什么是一维数组?什么是对象数组?吃金币游戏2.0版 新增炸弹功能 新增游戏倒计时功能 新增胜利失败检测功能 使用如鹏游戏引擎制作窗体 一维数组设置金币

    什么是数组? 数组的定义:是用统一的名字代表这批数据,用序号来区分各个数据.数组是无序的数据元素按有序的下标组成的集合,分配固定空间大小的一种容器. 如何理解:其实就是一个同时放很多数据的变量. a= ...