`
8850702
  • 浏览: 28349 次
文章分类
社区版块
存档分类
最新评论

安卓入门.为控件绑定监听器

 
阅读更多
//为控件绑定监听器


//1.获取代表控件的对象
private Button button;
button = (Button) findViewById(R.id.button1);

//2.定义一个类,实现监听器接口
class ButtonLister implements OnClickListener {

		@Override
		// 每点击Button一次,TextView上的字符串0,加1
		public void onClick(View v) {
			count++;
			textView.setText(count+"");//转为字符串
		}

	}

//3.生成监听器对象

//4.为控件绑定监听器对象


protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		button = (Button) findViewById(R.id.button1);//1.获取代表控件的对象
		
		ButtonLister buttonLister=new ButtonLister();//3.生成监听器对象

		button.setOnClickListener(buttonLister);//4.为控件绑定监听器对象
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics