最新国产好看的视频,伊人天堂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, "我的編號(hào):"+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)文章

最新評(píng)論

普洱| 龙岩市| 海盐县| 当涂县| 牡丹江市| 庆元县| 金寨县| 巩留县| 岑溪市| 四子王旗| 聊城市| 景德镇市| 郎溪县| 泸州市| 万全县| 雷州市| 奈曼旗| 靖边县| 临海市| 高州市| 榆林市| 青铜峡市| 贞丰县| 阿克苏市| 越西县| 山丹县| 唐山市| 泰来县| 和林格尔县| 买车| 平原县| 安福县| 黔东| 洪泽县| 仙游县| 偃师市| 八宿县| 汝州市| 新巴尔虎左旗| 兴化市| 嘉禾县|