焦点事件: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);
      }
    }
  });

事件(5)

 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 }
代码示例

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2021-11-17
  • 2021-12-28
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案