最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中回調(diào)接口的使用介紹

 更新時(shí)間:2013年06月17日 16:40:49   作者:  
回調(diào)接口在完成某些特殊的功能時(shí)還是蠻有用的,下面為大家分享下具體的使用方法,感興趣的朋友可以參考下哈
MainActivity如下:
復(fù)制代碼 代碼如下:

package cn.testcallback;
import android.os.Bundle;
import android.widget.Toast;
import android.app.Activity;
/**
* Demo描述:
* Android中回調(diào)接口的使用
*/
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();
}
});
}
}
}
//定義函數(shù),其中一個(gè)參數(shù)為CallBackInterface類型
private void showToast(int i, CallBackInterface callBackInterface) {
callBackInterface.callBackFunction(i);
}

//定義接口.且在接口中定義一個(gè)方法
public interface CallBackInterface {
public void callBackFunction(int i);
}
}

main.xml如下:
復(fù)制代碼 代碼如下:

<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>

相關(guān)文章

  • Android實(shí)現(xiàn)帶有刪除按鈕的EditText示例代碼

    Android實(shí)現(xiàn)帶有刪除按鈕的EditText示例代碼

    本文給大家介紹一個(gè)很實(shí)用的小控件,就是在Android系統(tǒng)的輸入框右邊加入一個(gè)小圖標(biāo),點(diǎn)擊小圖標(biāo)可以清除輸入框里面的內(nèi)容,IOS上面直接設(shè)置某個(gè)屬性就可以實(shí)現(xiàn)這一功能,但是Android原生EditText不具備此功能,所以要想實(shí)現(xiàn)這一功能我們需要重寫EditText。下面來看看吧。
    2016-12-12
  • Android網(wǎng)絡(luò)數(shù)據(jù)開關(guān)用法簡單示例

    Android網(wǎng)絡(luò)數(shù)據(jù)開關(guān)用法簡單示例

    這篇文章主要介紹了Android網(wǎng)絡(luò)數(shù)據(jù)開關(guān)用法,通過自定義函數(shù)調(diào)用系統(tǒng)服務(wù)實(shí)現(xiàn)開關(guān)功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • Kotlin?Navigation可視化開發(fā)詳解

    Kotlin?Navigation可視化開發(fā)詳解

    Navigation?是?JetPack?中的一個(gè)組件,用于方便的實(shí)現(xiàn)頁面的導(dǎo)航,所以抽象出了一個(gè)?destination?的概念,大部分情況一個(gè)?destination?就表示一個(gè)?Fragment,但是它同樣可以指代?Activity、其它的導(dǎo)航圖
    2023-02-02
  • Eclipse工程轉(zhuǎn)為兼容Android Studio模式的方法步驟圖文詳解

    Eclipse工程轉(zhuǎn)為兼容Android Studio模式的方法步驟圖文詳解

    這篇文章主要介紹了Eclipse工程轉(zhuǎn)為兼容Android Studio模式的方法步驟,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2017-12-12
  • Android mvvm之LiveData原理案例詳解

    Android mvvm之LiveData原理案例詳解

    這篇文章主要介紹了Android mvvm之LiveData原理案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Android利用Sensor實(shí)現(xiàn)傳感器功能

    Android利用Sensor實(shí)現(xiàn)傳感器功能

    這篇文章主要為大家詳細(xì)介紹了Android利用Sensor實(shí)現(xiàn)傳感器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Android開發(fā)實(shí)現(xiàn)在Wifi下獲取本地IP地址的方法

    Android開發(fā)實(shí)現(xiàn)在Wifi下獲取本地IP地址的方法

    這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)在Wifi下獲取本地IP地址的方法,涉及Android編程Wifi的調(diào)用及IP地址的獲取與轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下
    2017-09-09
  • Android  Retrofit和Rxjava的網(wǎng)絡(luò)請求

    Android Retrofit和Rxjava的網(wǎng)絡(luò)請求

    這篇文章主要介紹了Android Retrofit和Rxjava的網(wǎng)絡(luò)請求的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android應(yīng)用程序窗口(Activity)窗口對象(Window)創(chuàng)建指南

    Android應(yīng)用程序窗口(Activity)窗口對象(Window)創(chuàng)建指南

    本文將詳細(xì)介紹Android應(yīng)用程序窗口(Activity)的窗口對象(Window)的創(chuàng)建過程,需要了解的朋友可以參考下
    2012-12-12
  • Android自定義View旋轉(zhuǎn)圓形圖片

    Android自定義View旋轉(zhuǎn)圓形圖片

    這篇文章主要為大家詳細(xì)介紹了Android自定義View旋轉(zhuǎn)圓形圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01

最新評論

湛江市| 海安县| 石狮市| 同德县| 桃江县| 镇沅| 铜山县| 澳门| 永吉县| 济宁市| 米脂县| 福贡县| 丹寨县| 茌平县| 花莲市| 邵阳县| 东阳市| 栖霞市| 武定县| 平邑县| 瑞金市| 石渠县| 长丰县| 绥阳县| 郁南县| 定边县| 麻栗坡县| 陆良县| 微博| 班玛县| 昭平县| 衡阳县| 宁国市| 扶沟县| 嵊州市| 井冈山市| 绥德县| 彭山县| 广灵县| 张家川| 玉山县|