• 事件(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文件代码
  • 相关阅读:
    Platform创建WinCE内核时的编译错误
    evc4下载
    WinCE NK.bin与NK.nb0
    怎样安装SQL Server CE
    WinCE 5.0 & its eboot
    WinCE 5.0边做边学(4)
    nema协议解析
    wince romfs的一点讨论
    学习VC++时经常会遇到链接错误LNK2001
    wince 来电防火墙静音实现的几种办法
  • 原文地址:https://www.cnblogs.com/yang82/p/6953969.html
Copyright © 2020-2023  润新知