Dialog共通写法(两个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 ConfirmDialog : Dialog { private var supContext: Context? = null
private var dialogMsg: String? = ""
private var cacelButtonText: String? = ""
private var confirmButtonText: String? = ""
private var imageRes: Int = 0
private var backFlag: Boolean = true constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
} constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, backFlag: Boolean) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
} constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, imageRes: Int) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.imageRes = imageRes } constructor(supContext: Context, dialogMsg: String, cacelButtonText: String, confirmButtonText: String, backFlag: Boolean, imageRes: Int) : super(supContext) {
this.supContext = supContext
this.dialogMsg = dialogMsg
this.cacelButtonText = cacelButtonText
this.confirmButtonText = confirmButtonText
this.backFlag = backFlag
this.imageRes = imageRes
} //クリックリスナーインターフェース
var clickListenerInterface: ClickListenerInterface? = null interface ClickListenerInterface {
//確認
fun doConfirm() fun doCancel()
} override fun onBackPressed() {
if (backFlag) {
dismiss()
}
return
} 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.confirm_alert_dialog, null)
setContentView(view)
//メッセージ
val tvMsg = view.findViewById(R.id.confirm_msg_text) as TextView
//確認
val tvConfirm = view.findViewById(R.id.click_btn) as Button
//メッセージ
val tvCancel = view.findViewById(R.id.cancel_btn) as Button
//画像
val dialogImage = view.findViewById(R.id.dialog_image) as ImageView
if (imageRes == 0) {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(R.mipmap.info))
} else {
dialogImage.setImageDrawable(supContext!!.resources.getDrawable(imageRes))
}
tvMsg.text = dialogMsg
tvConfirm.text = confirmButtonText
tvCancel.text = cacelButtonText tvConfirm.setOnClickListener(clickListener())
tvCancel.setOnClickListener(clickListener()) setCancelable(false)
setCanceledOnTouchOutside(false) 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()
//ボタン
R.id.cancel_btn -> clickListenerInterface!!.doCancel()
}
}
}
}
怎么用:
val confirm = ConfirmDialog(this@MypageFragmentView, "ログアウトしてもよろしいでしょうか?", "いいえ", "はい")
confirm.setClicklistener(object : ConfirmDialog.ClickListenerInterface {
override fun doConfirm() { logoutApi(this@MypageFragmentView) confirm.dismiss()
} //いいえ
override fun doCancel() {
confirm.dismiss()
}
})
confirm.show()
val confirmDialog = ConfirmDialog(this@MyThemeWebView, msg, "いいえ", "はい", false)
confirmDialog.setOnKeyListener { dialog, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK && event!!.repeatCount == 0) {
handler.cancel()
}
false
}
confirmDialog.setClicklistener(object : ConfirmDialog.ClickListenerInterface {
override fun doConfirm() {
handler.proceed()
confirmDialog.dismiss()
}
//いいえ
override fun doCancel() {
handler.cancel()
confirmDialog.dismiss()
}
})
confirmDialog.show()
Dialog共通写法(两个button)的更多相关文章
- Dialog共通写法(一个button)
一个button的: package jp.co.hyakujushibank.view import android.app.Dialogimport android.content.Context ...
- Title共通写法
用: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_c ...
- 一个共通的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 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- 共通css初次尝试
1.网页的主要的html <@fn.html css=["${basePath}/css/help/guideCommon.css${versionControl}"]tit ...
- 共通脚本utils
/** * 模块名:共通脚本 * 程序名: 通用工具函数 **/ var utils = {}; /** * 格式化字符串 * 用法: .formatString("{0}-{1}" ...
- List排序共通代码
此共通方法可以根据特定字段进行排序 package com.gomecar.index.common.utils; import java.lang.reflect.Method; import ja ...
- iOS菜鸟学习--怎样避免两个button同一时候响应
在測试应用时.有时会变态的将两个UIButton同一时候按住来測试.结果就是两个button会同一时候响应,会出现同一时候push两个viewcontroller等非正常情况.为了避免用户误操作造成这 ...
随机推荐
- 精通AngularJS(三)深入scope,继承结构,事件系统和生命周期
深入探讨 Scope 作用域 每一个 $scope 都是类 Scope 的一个实例.类 Scope 拥有可以控制 scope 生命周期的方法,提供事件传播的能力,并支持模板渲染. 作用域的层次结构 让 ...
- Java类的静态块の一
类的静态块在类加载时候执行,执行早于构造函数,并且只执行一次. 下面这个例子可以帮助理解: package untility; public class A { // 静态块 static { A c ...
- 【转】Create Hello-JNI with Android Studio
[转]Create Hello-JNI with Android Studio From:https://codelabs.developers.google.com/codelabs/android ...
- [翻译] API测试的最佳实践 - 介绍
API测试的最佳实践 - 介绍 在上一篇“是什么让API测试很叼”一文中,我们讨论API与其他形式的软件测试的差异.部分是因为API之间的通信压根就没考虑让你能读懂,纯粹是为了方便计算机之间的交互而设 ...
- 了解springcloud
spring cloud比较不错的文章 https://blog.csdn.net/zhaozhenzuo/article/details/52803490?utm_source=blogxgwz9 ...
- python代理检测
import socket,threading,os,sys,queue,re socket.setdefaulttimeout(5) path=sys.path[0] if os.path.isfi ...
- UVA 12549 Sentry Robots (最小点覆盖)
这道题挺像hdu 5093 Battle ships的,不过那道题是要求最多放置的点数,而这道题是要求最小点覆盖. 顶点覆盖的定义是:在G中任意边至少有一个端点属于顶点集合S. 一个重要的位置有(x, ...
- ios项目icon和default图片命名规则
一.应用图片标准iOS控件里的图片资源,苹果已经做了相应的升级,我们需要操心的是应用自己的图片资源.就像当初为了支持iPhone 4而制作的@2x高分辨率版本(译者:以下简称高分)图片一样,我们要为i ...
- vue watch 监听
1.普通的watch data() { return { frontPoints: 0 } }, watch: { frontPoints(newValue, oldValue) { console. ...
- 爬虫5_python2_使用 Beautiful Soup 解析数据
使用 Beautiful Soup 解析数据(感谢东哥) 有的小伙伴们对写正则表达式的写法用得不熟练,没关系,我们还有一个更强大的工具,叫Beautiful Soup,有了它我们可以很方便地提取出HT ...