美文网首页
接口回调

接口回调

作者: 我叫杨毅 | 来源:发表于2020-08-24 16:03 被阅读0次

一.创建接口或内部接口

  public interface TwoFragmentInterface{
        void onListener(String id);
    }

二.在Adapter

1.设置全局变量

 private TwoFragmentInterface twoFragmentInterface;

2.添加set方法

 public void setTwoFragmentInterface(TwoFragmentInterface twoFragmentInterface) {
        this.twoFragmentInterface = twoFragmentInterface;
    }

3.在onBindViewHolder方法中使用

 helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                twoFragmentInterface.onListener(item.getReqStartTime());
            }
        });

三.在Activity

(实现接口和方法)

1.实现接口

public class TwoFragment extends BaseFragment implements TwoFragmentRecyclerViewAdapter.TwoFragmentInterface {
image.png

2.添加set方法

twoFragmentRecyclerViewAdapter.setTwoFragmentInterface(this);
image.png

3.实现中的点击方法

 @Override
    public void onListener(String id) {
        Log.e(TAG, "onListener: "+id );
    }

相关文章

  • Kotlin使用接口回调

    1.Java中的接口回调实现(支持多方法回调) 声明回调接口,初始化接口 使用接口回调(无参数) 使用接口回调(带...

  • Java回调深入理解

    1 接口回调 1.1 接口回调概念 什么是接口回调接口回调是指:可以把使用某一接口的类创建的对象的引用赋给该接口声...

  • Android Module之间数据传递

    方法一:使用接口回调 (1)在子module创建回调接口(参数可变) (2)在子module 实现类设置接口回调 ...

  • Android接口回调

    之前对接口回调一直有点模糊,会写但是理解的不透彻,今天记录一下自己理解的回调是什么。 接口回调是什么? 接口回调是...

  • Kotlin简单回调接口(lambda实现)

    注:适用于回调接口单个方法 1.方法无参无返回值回调 (1)声明回调接口,以及初始化接口 (2)接口方法的调用 (...

  • kotlinInterface

    注:适用于回调接口单个方法 1.方法无参无返回值回调 (1)声明回调接口,以及初始化接口 2.方法有参无返回值回调...

  • Fragment向Activity传递值

    一.Fragment向Activity传值的步骤 接口回调传递(5部曲) fragment中准备回调接口 接口中...

  • 接口回调

    实现fragment往Activity传值 接口回调是指:可以把使用某一接口的类创建的对象的引用赋给该接口声明的接...

  • 接口回调

    接口A: 类B: 类C:

  • 接口回调

    接口回调,其实就是将接口里面的内容(可能是接口里面数据需要传递),传递到实现这个接口的类中,看下面的是一个Asyn...

网友评论

      本文标题:接口回调

      本文链接:https://www.haomeiwen.com/subject/wjpnjktx.html