码迷,mamicode.com
首页 > 移动开发 > 详细

Android——button控件使用

时间:2015-09-06 18:20:39      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

a001.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6 
 7     <Button
 8         android:id="@+id/btnShow"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:text="显示吐司" />
12 
13 </LinearLayout>

A001.java

 1 package com.example.main;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.view.View;
 6 import android.view.View.OnClickListener;
 7 import android.widget.Button;
 8 import android.widget.Toast;
 9 
10 public class A001 extends Activity {
11 
12     @Override
13     protected void onCreate(Bundle savedInstanceState) {
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.a001);
16         
17         // 获取 button 控件
18         Button button = (Button) findViewById(R.id.btnShow);
19         
20         //button 点击事件
21         button.setOnClickListener(new OnClickListener() {
22             
23             @Override
24             public void onClick(View v) {
25                 //点击 button 显示吐司
26                 Toast.makeText(A001.this, "按钮控件", Toast.LENGTH_SHORT).show();
27             }
28         });
29     }
30 }

 

Android——button控件使用

标签:

原文地址:http://www.cnblogs.com/yuge790615/p/4786713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!