qqsheji
全部博文(54)
2016年(3)
2014年(8)
2013年(4)
2012年(2)
2011年(29)
2010年(8)
cynthia
浪花小雨
Phyllis6
fenzao
菱绿
poluy
damingge
anben197
hzzxsuni
分类: Java
2011-02-27 22:05:15
Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /* 新建一个Intent对象 */ Intent intent = new Intent(); /* 指定intent要启动的类 */ intent.setClass(Activity01.this, Activity02.class); /* 启动一个新的Activity */ startActivity(intent); /* 关闭当前的Activity */ Activity01.this.finish(); } });
Button button = (Button) findViewById(R.id.button1);button.setOnClickListener(new ButtonListener()); class ButtonListener implements OnClickListener{ public void onClick(View v) { /* 新建一个Intent对象 */ Intent intent = new Intent(); /* 指定intent要启动的类 */ intent.setClass(Activity01.this, Activity02.class); /* 启动一个新的Activity */ startActivity(intent); /* 关闭当前的Activity */ Activity01.this.finish(); } }
public class SimpleTest extends Activity implements View.OnClickListener{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new ButtonListener()); startBtn.setOnClickListener(this); } public void onClick(View v) { /* 新建一个Intent对象 */ Intent intent = new Intent(); /* 指定intent要启动的类 */ intent.setClass(Activity01.this, Activity02.class); /* 启动一个新的Activity */ startActivity(intent); /* 关闭当前的Activity */ Activity01.this.finish(); } }
checkbox监听器:
swimBox = (CheckBox)findViewById(R.id.swim); runBox = (CheckBox)findViewById(R.id.run); readBox = (CheckBox)findViewById(R.id.read); swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ //该方法的第一个参数是CompoundButton对象,第二个参数是isChecked是否选中 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked){ System.out.println("swimBox checked"); }else{ System.out.println("swimBox unchecked"); } } }); runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked){ System.out.println("runBox checked"); }else{ System.out.println("runBox unchecked"); } } }); readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stubrunBox if (isChecked){ System.out.println("readBox checked"); }else{ System.out.println("readBox unchecked"); } } });
swimBox = (CheckBox)findViewById(R.id.swim); runBox = (CheckBox)findViewById(R.id.run); readBox = (CheckBox)findViewById(R.id.read); BindCheckBoxListener(swimBox); BindCheckBoxListener(runBox); BindCheckBoxListener(readBox); public void BindCheckBoxListener(CheckBox checkBox){ checkBox.setOnCheckedChangeListener(new CheckBoxListen(checkBox)); } class CheckBoxListen implements OnCheckedChangeListener{ public CheckBox checkBox; public CheckBoxListen(CheckBox checkBox){ this.checkBox = checkBox; } public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stubrunBox if (isChecked){ System.out.println(checkBox+"checked"); }else{ System.out.println(checkBox+"unchecked"); } } }
上一篇:关于javascript 图片上传预览图
下一篇:java 读取excel文件
登录 注册