Button在android程序中的初始化思路

[ 2011-12-25 10:12:15 | 作者: admin ]
字号: | |
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){}
                     //自己的代码
                });
[最后修改由 admin, 于 2011-12-25 10:13:10]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1768

这篇日志没有评论。

此日志不可发表评论。