国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汶上县| 舟山市| 廊坊市| 望谟县| 基隆市| 锦州市| 古交市| 育儿| 龙泉市| 玉龙| 临邑县| 平湖市| 长寿区| 沧州市| 镇原县| 崇明县| 阜南县| 松阳县| 邳州市| 辛集市| 武邑县| 彭山县| 垫江县| 玉林市| 仙游县| 仪陇县| 托里县| 建宁县| 丹棱县| 吉木乃县| 嘉鱼县| 涿鹿县| 呼伦贝尔市| 武宁县| 清丰县| 永丰县| 兴业县| 云和县| 遵义县| 老河口市| 会理县|