Dialog共通写法(一个button)
一个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)的更多相关文章
- Dialog共通写法(两个button)
package jp.co.hyakujushibank.view import android.app.Dialogimport android.content.Contextimport andr ...
- Title共通写法
用: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_c ...
- 2016.8.19 在dialog上增加一个button出现错误:failed to execute setAttribute on Element...
目标:想要在dialog上多加一个button. 语法来自: http://api.jqueryui.com/dialog/#option-buttons 可见新增在dialog上的button要 ...
- 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)
http://www.cnblogs.com/xqin/archive/2013/06/06/3120887.html 前言 我写代码喜欢提取一些共通的东西出来,之前的一篇博客中说了如何用一个共通的v ...
- 一个共通的viewModel搞定所有的分页查询一览及数据导出(easyui + knockoutjs + mvc4.0)
前言 大家看标题就明白了我想写什么了,在做企业信息化系统中可能大家写的最多的一种页面就是查询页面了.其实每个查询页面,除了条件不太一样,数据不太一样,其它的其实都差不多.所以我就想提取一些共通的东西出 ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- rails跑通第一个demo
rails -h 查看帮助 Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby bina ...
- 共通css初次尝试
1.网页的主要的html <@fn.html css=["${basePath}/css/help/guideCommon.css${versionControl}"]tit ...
- iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
//直接代码 只包含 折叠展开字典的处理搭建#import "CFViewController.h" @interface CFViewController ()<UITab ...
随机推荐
- IE6下png背景不透明——张鑫旭博客读书笔记
从今天开始跟着大牛张鑫旭的步伐,每天进步一点点 问题:IE6不支持png背景透明或半透明 一.可解决的方法 补充:css滤镜主要是用来实现图像的各种特殊效果.(了解) css滤镜的标识符是“filte ...
- 自定义Mega菜单的巧妙实现
查看了<云制造>官网源码,为其mega菜单的巧妙实现打call. 其另辟蹊径,采取父级主控分支的方法,仅对父级“增加/删除”控制标识,从而控制子层显示. <!DOCTYPE html ...
- iOS 如何解决并发请求时,只接受最后一个请求返回的结果
大致意思是 虽然NSOperation 的cancel 并不能取消请求,但是可以对这个NSOperation进行标记. 当cancel 属性是YES时,表明 NSOperation虽然已经执行,并 ...
- copyin函数
详见:http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.kerneltechref%2Fdoc%2Fk ...
- Oracle种常用性能监控SQL语句
--Oracle常用性能监控SQL语句 --1 SELECT * FROM SYS.V_$SQLAREA WHERE DISK_READS > 100; --2 监控事例的等待 SELECT E ...
- NBUT 1115 Cirno's Trick (水)
题意: 给出多个double数,去掉其最小的和最大的,再对余下的求均值. 思路: 再输入时将最大和最小去掉,顺便统计非最值的和,输出时除一下个数即可. #include <bits/stdc++ ...
- maven项目jsp无法识别jstl的解决办法
EL表达式无效是因为maven项目的jsp不识别jstl,只要在web-APP 标签中引入命名空间 xmlns="http://xmlns.jcp.org/xml/ns/javaee&quo ...
- ssh的server安装和安装指定版本的软件的方法
ssh程序分为有客户端程序openssh-client和服务端程序openssh-server.如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...
- Web开发面临的挑战主要有哪些?
摘要:要成为一名高效的Web开发者,这需要我们做很多工作,来提高我们的工作方式,以及改善我们的劳动成果.而在开发中难免会遇到一些困难,从前端到后端. 导读:要成为一名高效的Web开发者,这需要我们做很 ...
- Go统计键盘输入随机字母的个数
package main import "fmt" //通过键盘输入20个小写字母,统计个数 func main(){ //通过键盘器获取字符 var arr [20]byte f ...