- package com.hangsheng.button;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
-
- public class Ex07_WidgetButtonActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- find_and_modify_button();
- }
- private void find_and_modify_button(){
- Button button =(Button)findViewById(R.id.button);
- button.setOnClickListener(button_listener);
-
- };
- private Button.OnClickListener button_listener =new Button.OnClickListener(){
- @Override
- public void onClick(View v) {
-
- setTitle("button被点击了一下");
- }
- };
- }
布局模板文件main.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
-
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
-
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="这是Button" />
-
- </LinearLayout>
Android下按钮的使用方法
原文:http://www.cnblogs.com/zarea/p/4416224.html