首页 > 其他 > 详细

有关Botton的用法(二)

时间:2015-10-08 14:23:19      阅读:212      评论:0      收藏:0      [点我收藏+]

Steps:

1.tell android you are interested in listening to a button click

2.bring your xml button inside java

3.tell your java button whose responding when it‘s clicked

4.what should happen when button is clicked

1     <Button
2         android:layout_width="wrap_content"
3         android:layout_height="wrap_content"
4         android:text="Button1"
5         android:id="@+id/button1"
6         android:layout_below="@+id/textView"
7         android:layout_alignParentLeft="true"
8         android:layout_alignParentStart="true" />

 

 1 public class MainActivity extends Activity implements OnClickListener {//1.tell android you are interested in listening to a button click
 2 
 3     Button button;
 4     @Override
 5     protected void onCreate(Bundle savedInstanceState) {
 6         super.onCreate(savedInstanceState);
 7         setContentView(R.layout.activity_main);
 8         button = (Button)findViewById(R.id.button1);//2.bring your xml button inside java
 9         button.setOnClickListener(this);//3.tell your java button whose responding when it‘s clicked
10     }
11 
12     @Override//4.what should happen when button is clicked
13     public void onClick(View v) {
14         Log.e("MainActivity","Clicked1");
15     }
16 
17 }

 

有关Botton的用法(二)

原文:http://www.cnblogs.com/turtle920/p/4860740.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!