zoukankan      html  css  js  c++  java
  • 事件(1)

    事件三要素
      事件源:事件发生的来源
      事件:行为(点击,触摸...)
      监听器:当事件发送时,所要做的事情


     onClickListener(单击事件)
      组件.setOnClickListener(new OnClickListener(){
      @Override
        public void onClick(View v) {
          String str=et.getText().toString();
          tv.setText(str);
        }
      });

     1 public class Click extends Activity{
     2     private Button bt;            //定义按钮
     3     private TextView tv;        //定义信息显示组件
     4     private EditText et;        //定义文本输入组件
     5     
     6     protected void onCreate(Bundle savedInstanceState) {
     7         super.onCreate(savedInstanceState);
     8         setContentView(R.layout.event);
     9         et=(EditText)findViewById(R.id.ete1);            //取得文本编辑组件
    10         bt=(Button)findViewById(R.id.bte1);                //取得按钮
    11         tv=(TextView)findViewById(R.id.tve1);            //取得文本显示组件
    12         //设置监听器,匿名内部类
    13         bt.setOnClickListener(new OnClickListener(){
    14             @Override
    15             public void onClick(View v) {
    16                 String str=et.getText().toString();        //取得文本框输入内容
    17                 tv.setText(str);                        //设置文本显示
    18             }
    19         });
    代码示例
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:orientation="vertical"
     4     android:layout_width="fill_parent" 
     5     android:layout_height="fill_parent" 
     6     >
     7        <EditText
     8             android:id="@+id/ete1"
     9            android:layout_width="fill_parent" 
    10             android:layout_height="wrap_content" 
    11             android:background="#00FF00"
    12       />
    13         <Button
    14             android:id="@+id/bte1"
    15           android:layout_width="fill_parent" 
    16                 android:layout_height="wrap_content" 
    17             android:text="确定"
    18      />
    19      
    20       <TextView
    21           android:id="@+id/tve1"
    22         android:layout_width="fill_parent" 
    23                 android:layout_height="wrap_content" 
    24            android:background="#FF0000"
    25       />
    26 </LinearLayout>            
    xml文件代码
  • 相关阅读:
    亚像素
    dmysql 与QT的连接
    opencv中ptr的使用
    对图片对比度和亮度的理解
    opencv中的各种滤波设计
    人脸检测相关介绍
    opencv中相关的矩阵运算
    形态学处理
    阀值化 threshold
    Python深浅拷贝
  • 原文地址:https://www.cnblogs.com/yang82/p/6953969.html
Copyright © 2011-2022 走看看