菜鸟lei的学习成长空间

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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){}
            //自己的代码
        });

posted on 2011-08-13 18:19  菜鸟-雷  阅读(926)  评论(0编辑  收藏  举报