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

    焦点事件:OnFocusChangeListener
      et.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
          if(hasFocus){
            et.setText("");
          }else{
            String str=et.getText().toString();
            tv.setText(str);
          }
        }
      });

     1 package com.hh;
     2 
     3 import android.app.Activity;
     4 import android.os.Bundle;
     5 import android.view.View;
     6 import android.view.View.OnFocusChangeListener;
     7 import android.widget.EditText;
     8 import android.widget.TextView;
     9 
    10 public class Day061 extends Activity{
    11     private EditText et;
    12     private TextView tv;
    13     protected void onCreate(Bundle savedInstanceState) {
    14         super.onCreate(savedInstanceState);
    15         setContentView(R.layout.day06focus);
    16         tv=(TextView) findViewById(R.id.tv061);
    17         et=(EditText) findViewById(R.id.et061);
    18         et.setOnFocusChangeListener(new OnFocusChangeListener() {
    19             
    20             @Override
    21             public void onFocusChange(View v, boolean hasFocus) {
    22                 if(hasFocus){
    23                     et.setText("");
    24                 }else{
    25                     String str=et.getText().toString();
    26                     tv.setText(str);
    27                 }
    28             }
    29         });
    30     }
    31 }
    代码示例
     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       <TextView
     8           android:id="@+id/tv061"
     9         android:layout_width="fill_parent" 
    10         android:layout_height="wrap_content" 
    11            android:background="#FF0000"
    12       />
    13        <EditText
    14                android:id="@+id/et061"
    15             android:layout_width="fill_parent" 
    16             android:layout_height="wrap_content"
    17        />
    18        <EditText
    19                android:id="@+id/et062"
    20             android:layout_width="fill_parent" 
    21             android:layout_height="wrap_content"
    22        />
    23 </LinearLayout>
    xml配置文件
  • 相关阅读:
    寒号鸟不是鸟,爸爸你会吃。
    思杨的课外班的思考
    一年级第二学期
    City
    SON
    python(16)——生成器
    python(15)——迭代和迭代器
    python(14)——python中的数学模块
    python(13)——lambda表达式
    Python(12)——变量作用域及闭包操作
  • 原文地址:https://www.cnblogs.com/yang82/p/6979794.html
Copyright © 2011-2022 走看看