gpt4 book ai didi

Android中回调接口的使用介绍

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Android中回调接口的使用介绍由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

MainActivity如下

复制代码 代码如下

package cn.testcallback; import android.os.Bundle; import android.widget.Toast; import android.app.Activity; /** * Demo描述: * Android中回调接口的使用 */ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init() { for (int i = 0; i < 10000; i++) { if (i == 9527) { showToast(i, new CallBackInterface() { @Override public void callBackFunction(int i) { Toast.makeText(MainActivity.this, "我的编号:"+i, Toast.LENGTH_LONG).show(); } }); } } } //定义函数,其中一个参数为CallBackInterface类型 private void showToast(int i, CallBackInterface callBackInterface) { callBackInterface.callBackFunction(i); } //定义接口.且在接口中定义一个方法 public interface CallBackInterface { public void callBackFunction(int i); } } 。

main.xml如下

复制代码 代码如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:layout_centerInParent="true" /> </RelativeLayout> 。

最后此篇关于Android中回调接口的使用介绍的文章就讲到这里了,如果你想了解更多关于Android中回调接口的使用介绍的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com