惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tor Project blog
月光博客
月光博客
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
量子位
A
Arctic Wolf
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Full Disclosure
C
Cisco Blogs
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
PCI Perspectives
PCI Perspectives
S
Security Affairs
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
H
Hacker News: Front Page
S
Securelist
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
罗磊的独立博客
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Security @ Cisco Blogs
The Last Watchdog
The Last Watchdog
小众软件
小众软件
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Last Week in AI
Last Week in AI
爱范儿
爱范儿
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog

博客园 - y丶innocence

临时111 RecyclerView 数据多时无法滑动:ConstraintLayout 约束高度修复笔记 Android Kotlin OkHttp3 WebSocket 长连接与 Gson 数据解析系统笔记 Android + Kotlin + OkHttp WebSocket 相关概念与使用流程笔记(TLS/证书 + 鉴权/会话) AI对话导出markdown格式流程 代理转发 分享文件 面向全球的app的excel导出和kotlin IO原理 安卓导出笔记(未整理) 0.7 动画 0.4 View 工作流程 0.3 view 滑动冲突 13. Jetpack 0. 安卓开发艺术探索参考资料 12. Material Design 7. 持久化技术 5. Fragment java 基础 4. UI 开发 3. Activity 2.2 Kotlin 面向对象 2.3 Kotlin高级 2.1 Kotlin基础 1. Android简介 [OpenJudge] 反正切函数的应用 (枚举)(数学) [OpenJudge] 摘花生 (模拟)
java&kotlin listener
y丶innocence · 2026-03-18 · via 博客园 - y丶innocence
private MyListener myListener;
public void setMyListener(MyListener myListener) {
    this.myListener = myListener;
}
public interface MyListener {
    void myFun(long timeInMillis);
}
fragment.setMyListener{
            mModel.myAnotherFun(it)
        }
        


private var myListener: MyListener? = null
fun setMyListener(myListener: MyListener) {
    this.myListener = myListener
}
fun interface MyListener {
    fun myFun(timeInMillis: Long)
}
fragment.setMyListener{
    mModel.myAnotherFun(it)
}



private var myListener: MyListener? = null
fun setMyListener(myListener: MyListener) {
    this.myListener = myListener
}
interface MyListener {
    fun myFun(timeInMillis: Long)
}
fragment.setMyListener( object: MyListener {
    override fun myFun(timeInMillis: Long) {       // 必须实现接口
        mModel.myAnotherFun(timeInMillis) 
    }
}
                       
                       
// 使用函数类型替代接口
private var myListener: ((Long) -> Unit)? = null
// 使用函数类型参数
fun setMyListener(listener: (Long) -> Unit) {
    this.myListener = listener
}
// 使用(可以直接使用Lambda):
fragment.setMyListener { time ->
    mModel.myAnotherFun(time)
}
// 或使用it简写:
fragment.setMyListener {
    mModel.myAnotherFun(it)
}