本文共 498 字,大约阅读时间需要 1 分钟。
android.widget.Button
1.layout的xml中先设置好button的属性,包括id <Button android:id="@+id/button1" android:text="button_name" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>2.在要用到button的Activity中实例化button对象
Button button1=(Button)findViewById(R.id.button_id); 3.添加监听器 button1.setOnClickListener(new View.OnClickListener(){ @override public void onClick(View v){} //自己的代码 });本文转自leipei博客园博客,原文链接:http://www.cnblogs.com/leipei2352/archive/2011/08/13/2137452.html,如需转载请自行联系原作者