国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中回調接口的使用介紹

2020-04-11 12:08:47
字體:
來源:轉載
供稿:網友
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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平安县| 正安县| 邯郸县| 开鲁县| 万州区| 巫山县| 山东省| 吉林市| 遵化市| 临夏县| 新邵县| 元江| 固原市| 广宁县| 凤翔县| 云南省| 汶川县| 泌阳县| 武夷山市| 南昌市| 千阳县| 东阳市| 河池市| 新干县| 维西| 阜南县| 清远市| 富川| 商丘市| 双峰县| 玛多县| 芒康县| 宣城市| 德阳市| 六盘水市| 曲靖市| 军事| 华安县| 英吉沙县| 施秉县| 凌海市|