Chinaunix首页 | 论坛 | 博客

OS

  • 博客访问: 2230574
  • 博文数量: 691
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2660
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-05 12:49
个人简介

不浮躁

文章分类

全部博文(691)

文章存档

2019年(1)

2017年(12)

2016年(99)

2015年(207)

2014年(372)

分类: Android平台

2015-11-27 11:09:33

原文地址:单击事件 作者:luozhiyong131

在手机使用的过程之中,经常要使用按钮触发一些基本的操作,这个时候就可以通过单击事件完成,单击事件使用View.OnClickListener接口进行事件的处

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout                     ?    线性布局管理器
  3.     xmlns:android=""
  4.     android:orientation="vertical"         ?    所有组件垂直摆放
  5.     android:layout_width="fill_parent"        ?    布局管理器宽度为屏幕宽度
  6.     android:layout_height="fill_parent">        ?    布局管理器高度为屏幕高度
  7.     <EditText                    ?    定义文本编辑框
  8.         android:id="@+id/myed"        ?    文本编辑框ID,程序中使用
  9.         android:layout_width="wrap_content"    ?    组件宽度为文字宽度
  10.         android:layout_height="wrap_content"     ?    组件高度为文字高度
  11.         android:text="请输入您的姓名"/>        ?    组件的默认文字
  12.     <Button                    ?    定义按钮组件
  13.         android:id="@+id/mybut"        ?    按钮组件ID,程序中使用
  14.         android:layout_width="wrap_content"    ?    组件宽度为文字宽度
  15.         android:layout_height="wrap_content"     ?    组件高度为文字高度
  16.         android:text="显示输入信息"/>        ?    组件的默认文字
  17.     <TextView                    ?    定义文本显示框
  18.         android:id="@+id/mytext"        ?    文本编辑框ID,程序中使用
  19.         android:layout_width="wrap_content"    ?    组件宽度为文字宽度
  20.         android:layout_height="wrap_content"     ?    组件高度为文字高度
  21.         android:text="输入的信息是:"/>        ?    组件的默认文字
  22. </LinearLayout>


点击(此处)折叠或打开

  1. package org.lxh.demo;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.TextView;
  9. public class MyClickDemo extends Activity {
  10.     private TextView showView = null ;            // 定义信息显示组件
  11.     private EditText edit = null ;            // 定义文本输入组件
  12.     private Button but = null ;            // 定义按钮
  13.     @Override
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         super.setContentView(R.layout.main);
  17.         this.but = (Button) super.findViewById(R.id.mybut) ;    // 取得按钮
  18.         this.showView = (TextView) super.findViewById(R.id.mytext) ;// 取得文本显示组件
  19.         this.edit = (EditText) super.findViewById(R.id.myed) ;    // 取得文本编辑组件
  20.         but.setOnClickListener(new ShowListener()) ;        // 定义监听
  21.     }
  22.     private class ShowListener implements OnClickListener {    // 定义监听处理程序
  23.         public void onClick(View v) {
  24.             String info = edit.getText().toString() ;// 取得文本框输入内容
  25.             showView.setText("输入的内容是:" + info) ; // 设置文本显示组件
  26.         }
  27.     }
  28. }

020602_单击事件.ppt
阅读(1192) | 评论(0) | 转发(0) |
0

上一篇:下拉列表监听

下一篇:相对布局管理器

给主人留下些什么吧!~~