分2个角色,我和你
1个接口,通道工具,通过这个工具来传递对话
1.我 我给你打电话,问你个问题获取答案
调用你的方法获取我想要的答案
//在需要问的时候调用
DetailActivity.callRefresh(object :DetailActivity.CommentCountRefresh{
override fun reFreshCount(str: String) {
str.logE()
helper.itemView.news_publish_time0.text = str
}
})
2.你
class DetailActivity : Activity(){
//这个是DetailActivity 里面的方法,在合适的时机调用,把答案告诉对方
fun callback(){
//调用接口的刷新方法 //表明我现在想好了答案,我现在要告诉你答案
commentR!!.reFreshCount(totalCount.toString())
}
//定义接口
interface CommentCountRefresh {
fun reFreshCount(str:String)
}
companion object {
//接口实例
var commentR: CommentCountRefresh? = null
//这个方法是提供给别人来问问题的
fun callRefresh(commentCountRefresh:CommentCountRefresh) {
this.commentR = commentCountRefresh
}
}
}
java 的方式
public class JzvdStd extends Jzvd {
@Override
public void onAutoCompletion() {
super.onAutoCompletion();
cancelDismissControlViewTimer();
videoComplete.videoOver(true);
}
//内部类
public VideoComplete videoComplete;
public void setVideoComplete(VideoComplete videoComplete){
this.videoComplete = videoComplete;
}
//定义
public interface VideoComplete {
void videoOver(boolean isOver);
}
//类似view.onclicklistener 接口
class VideoDetailActivity : BaseAppActivity(), BaseQuickAdapter.RequestLoadMoreListener,JzvdStd.VideoComplete{
private void initView(){
//注册
jz_video.setVideoComplete(this)
}
//重写实现方法
override fun videoOver(isOver: Boolean) {
("播放完成").logE();
finish()
}
}
网友评论