Android中回调接口使用实例
2014-03-10 15:28
471 查看
MainActivity如下:
ThreadSubclass如下:
main.xml如下:
package cc.cn; import cc.cn.ThreadSubclass.YourListener; import android.app.Activity; import android.os.Bundle; /** * Demo描述: * Android中回调接口使用实例 */ public class MainActivity extends Activity { private ThreadSubclass mThreadSubclass; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init(){ mThreadSubclass=new ThreadSubclass(); mThreadSubclass.setYourListener(new YourListener() { @Override public void onSomeChange(String info,int i) { System.out.println("------> info="+info); System.out.println("------> i="+i); } }); mThreadSubclass.start(); } }
ThreadSubclass如下:
package cc.cn; public class ThreadSubclass extends Thread { private YourListener mYourListener=null; @Override public void run() { super.run(); for (int i = 0; i < 5; i++) { System.out.println("Now is "+i); } if (mYourListener!=null) { mYourListener.onSomeChange("输入已经完毕",9527); } } //回调接口(监听器) public interface YourListener { public void onSomeChange(String info,int i); } //设置回调接口(监听器)的方法 public void setYourListener(YourListener yourListener) { mYourListener = yourListener; } }
main.xml如下:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Android中回调接口使用实例" android:layout_centerInParent="true" /> </RelativeLayout>
相关文章推荐
- Android中回调接口使用实例
- android sdk虚拟机配置方法
- Android数据的四种存储方式
- android 没有main函数,怎么找到程序执行入口呢?以及activity主要生命周期的方法说明
- Android通过findViewById()获取控件为NULL
- 深入理解Android的startservice和bindservice
- Android的按钮单击事件及监听器的实现方式
- android之BroadcastReceiver应用详解
- Android PageAdapter翻译
- Android性能调优
- 为Android内核添加新驱动,并添加menuconfig菜单
- Android优秀开源项目[持续更新~欢迎推荐~]
- android Animations 动画效果(一)
- Android中的Selector的用法
- android第三步电话拔号器
- Android 开发中的专业词语
- 关于Android中的armeabi 和armeabi-v7a
- Android中的Handler的post方法详解
- Android移植教程
- Android 项目中文件夹作用(res文件夹详细介绍)