Android View添加 Listener 小技巧示例
2010-06-19 17:48:00 来源:WEB开发网import android.view.View;
public class TestOnClickListener extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void myClickHandler(View target){
switch (target.getId()) {
case R.id.Button01:
setTitle("myClickHandler01");
break;
case R.id.Button02:
setTitle("myClickHandler02");
break;
}
}
}
package com.ray.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class TestOnClickListener extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void myClickHandler(View target){
switch (target.getId()) {
case R.id.Button01:
setTitle("myClickHandler01");
break;
case R.id.Button02:
setTitle("myClickHandler02");
break;
}
}
}
参考文章:《UI framework changes in Android 1.6》(需翻墙)
更多精彩
赞助商链接