事件监听篇---第二篇

下面是各种常用控件的事件监听的使用

①EditText(编辑框)的事件监听---OnKeyListener

②RadioGroup、RadioButton(单选按钮)的事件监听---OnCheckedChangeListener

③CheckBox(多选按钮)的事件监听---OnCheckedChangeListener

④Spinner(下拉列表)的事件监听---OnItemSelectedListener

⑤Menu(菜单)的事件处理---onMenuItemSelected

⑥Dialog(对话框)的事件监听---DialogInterface.OnClickListener()

第一个例子:EditText的事件监听

  1. 1 package org.hualang.eventtest2;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.os.Bundle;
  5. 5 import android.view.KeyEvent;
  6. 6 import android.view.View;
  7. 7 import android.widget.EditText;
  8. 8 import android.widget.TextView;
  9. 9
  10. 10 public class EventTest2 extends Activity {
  11. 11 /** Called when the activity is first created. */
  12. 12 private TextView mytext;
  13. 13 private EditText edittext;
  14. 14 @Override
  15. 15 public void onCreate(Bundle savedInstanceState) {
  16. 16 super.onCreate(savedInstanceState);
  17. 17 setContentView(R.layout.main);
  18. 18 mytext = (TextView)findViewById(R.id.mytext);
  19. 19 edittext = (EditText)findViewById(R.id.edittext);
  20. 20 /**
  21. 21 * 设置当EditText为空,则提示“请输入账号”
  22. 22 * 在配置文件main.xml中可以用android:hint="请输入账号"来实现
  23. 23 */
  24. 24 edittext.setHint("请输入账号");
  25. 25 //下面为EditText事件监听
  26. 26 edittext.setOnKeyListener(new EditText.OnKeyListener()
  27. 27 {
  28. 28
  29. 29 @Override
  30. 30 public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
  31. 31 //得到文字,显示在TextView中
  32. 32 mytext.setText("内容:"+edittext.getText().toString());
  33. 33 return false;
  34. 34 }
  35. 35
  36. 36 });
  37. 37 }
  38. 38 }

main.xml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 android:orientation="vertical"
  4. 4 android:layout_width="fill_parent"
  5. 5 android:layout_height="fill_parent"
  6. 6 >
  7. 7 <TextView
  8. 8 android:layout_width="fill_parent"
  9. 9 android:layout_height="wrap_content"
  10. 10 android:id="@+id/mytext"
  11. 11 />
  12. 12 <EditText
  13. 13 android:id="@+id/edittext"
  14. 14 android:layout_width="fill_parent"
  15. 15 android:layout_height="wrap_content"
  16. 16 android:textSize="10pt"
  17. 17 />
  18. 18 </LinearLayout>

运行结果如下:


 

第二个例子:单选按钮的事件监听处理

  1. 1 package org.hualang.eventtest;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.os.Bundle;
  5. 5 import android.view.Gravity;
  6. 6 import android.widget.RadioButton;
  7. 7 import android.widget.RadioGroup;
  8. 8 import android.widget.Toast;
  9. 9
  10. 10 public class EventTest3 extends Activity {
  11. 11 /** Called when the activity is first created. */
  12. 12 private RadioGroup group;
  13. 13 private RadioButton radio1,radio2,radio3,radio4;
  14. 14 @Override
  15. 15 public void onCreate(Bundle savedInstanceState) {
  16. 16 super.onCreate(savedInstanceState);
  17. 17 setContentView(R.layout.main);
  18. 18
  19. 19 group = (RadioGroup)findViewById(R.id.radiogroup1);
  20. 20 radio1 = (RadioButton)findViewById(R.id.button1);
  21. 21 radio2 = (RadioButton)findViewById(R.id.button2);
  22. 22 radio3 = (RadioButton)findViewById(R.id.button3);
  23. 23 radio4 = (RadioButton)findViewById(R.id.button4);
  24. 24
  25. 25 group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  26. 26
  27. 27 @Override
  28. 28 public void onCheckedChanged(RadioGroup group, int checkedId) {
  29. 29 // TODO Auto-generated method stub
  30. 30 if (checkedId == radio2.getId())
  31. 31 {
  32. 32 showMessage("正确答案:" + radio2.getText()+",恭喜你,答对了");
  33. 33 }
  34. 34 else
  35. 35 {
  36. 36 showMessage("对不起,虽然很多,但不是公认的最多");
  37. 37 }
  38. 38 }
  39. 39 });
  40. 40 }
  41. 41 public void showMessage(String str)
  42. 42 {
  43. 43 Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
  44. 44 toast.setGravity(Gravity.TOP, 0, 220);
  45. 45 toast.show();
  46. 46 }
  47. 47 }

main.xml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 android:orientation="vertical"
  4. 4 android:layout_width="fill_parent"
  5. 5 android:layout_height="fill_parent"
  6. 6 >
  7. 7 <TextView
  8. 8 android:id="@+id/mytextview"
  9. 9 android:layout_width="fill_parent"
  10. 10 android:layout_height="wrap_content"
  11. 11 android:text="哪个城市的美女最多?"
  12. 12 />
  13. 13 <RadioGroup
  14. 14 android:id="@+id/radiogroup1"
  15. 15 android:layout_width="wrap_content"
  16. 16 android:layout_height="wrap_content"
  17. 17 android:orientation="vertical"
  18. 18 >
  19. 19 <RadioButton
  20. 20 android:id="@+id/button1"
  21. 21 android:layout_width="wrap_content"
  22. 22 android:layout_height="wrap_content"
  23. 23 android:text="杭州"
  24. 24 />
  25. 25 <RadioButton
  26. 26 android:id="@+id/button2"
  27. 27 android:layout_width="wrap_content"
  28. 28 android:layout_height="wrap_content"
  29. 29 android:text="重庆"
  30. 30 />
  31. 31 <RadioButton
  32. 32 android:id="@+id/button3"
  33. 33 android:layout_width="wrap_content"
  34. 34 android:layout_height="wrap_content"
  35. 35 android:text="成都"
  36. 36 />
  37. 37 <RadioButton
  38. 38 android:id="@+id/button4"
  39. 39 android:layout_width="wrap_content"
  40. 40 android:layout_height="wrap_content"
  41. 41 android:text="香港"
  42. 42 />
  43. 43 </RadioGroup>
  44. 44 </LinearLayout>

运行结果如下:

第三个例子:复选框的事件处理

  1. 1 package org.hualang.eventtest4;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.os.Bundle;
  5. 5 import android.view.Gravity;
  6. 6 import android.view.View;
  7. 7 import android.widget.Button;
  8. 8 import android.widget.CheckBox;
  9. 9 import android.widget.CompoundButton;
  10. 10 import android.widget.CompoundButton.OnCheckedChangeListener;
  11. 11 import android.widget.Toast;
  12. 12
  13. 13 public class EventTest4 extends Activity {
  14. 14 /** Called when the activity is first created. */
  15. 15 private CheckBox ch1,ch2,ch3,ch4,ch5;
  16. 16 private Button mybutton;
  17. 17 @Override
  18. 18 public void onCreate(Bundle savedInstanceState) {
  19. 19 super.onCreate(savedInstanceState);
  20. 20 setContentView(R.layout.main);
  21. 21
  22. 22 mybutton = (Button)findViewById(R.id.mybutton);
  23. 23 ch1 = (CheckBox)findViewById(R.id.check1);
  24. 24 ch2 = (CheckBox)findViewById(R.id.check2);
  25. 25 ch3 = (CheckBox)findViewById(R.id.check3);
  26. 26 ch4 = (CheckBox)findViewById(R.id.check4);
  27. 27 ch5 = (CheckBox)findViewById(R.id.check5);
  28. 28
  29. 29 ch1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
  30. 30 {
  31. 31
  32. 32 @Override
  33. 33 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
  34. 34 // TODO Auto-generated method stub
  35. 35 if(ch1.isChecked())
  36. 36 {
  37. 37 showMessage("你选择了"+ch1.getText());
  38. 38 }
  39. 39 }
  40. 40
  41. 41 });
  42. 42 ch2.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
  43. 43 {
  44. 44
  45. 45 @Override
  46. 46 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
  47. 47 // TODO Auto-generated method stub
  48. 48 if(ch3.isChecked())
  49. 49 {
  50. 50 showMessage("你选择了"+ch2.getText());
  51. 51 }
  52. 52 }
  53. 53
  54. 54 });
  55. 55 ch3.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
  56. 56 {
  57. 57
  58. 58 @Override
  59. 59 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
  60. 60 // TODO Auto-generated method stub
  61. 61 if(ch3.isChecked())
  62. 62 {
  63. 63 showMessage("你选择了"+ch3.getText());
  64. 64 }
  65. 65 }
  66. 66
  67. 67 });
  68. 68 ch4.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
  69. 69 {
  70. 70
  71. 71 @Override
  72. 72 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
  73. 73 // TODO Auto-generated method stub
  74. 74 if(ch4.isChecked())
  75. 75 {
  76. 76 showMessage("你选择了"+ch4.getText());
  77. 77 }
  78. 78 }
  79. 79
  80. 80 });
  81. 81 ch5.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
  82. 82 {
  83. 83
  84. 84 @Override
  85. 85 public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
  86. 86 // TODO Auto-generated method stub
  87. 87 if(ch5.isChecked())
  88. 88 {
  89. 89 showMessage("你选择了"+ch5.getText());
  90. 90 }
  91. 91 }
  92. 92
  93. 93 });
  94. 94
  95. 95 mybutton.setOnClickListener(new Button.OnClickListener()
  96. 96 {
  97. 97
  98. 98 @Override
  99. 99 public void onClick(View arg0) {
  100. 100 // TODO Auto-generated method stub
  101. 101 int num = 0;
  102. 102 if(ch1.isChecked())
  103. 103 {
  104. 104 num++;
  105. 105 }
  106. 106 if(ch2.isChecked())
  107. 107 {
  108. 108 num++;
  109. 109 }
  110. 110 if(ch3.isChecked())
  111. 111 {
  112. 112 num++;
  113. 113 }
  114. 114 if(ch4.isChecked())
  115. 115 {
  116. 116 num++;
  117. 117 }
  118. 118 if(ch5.isChecked())
  119. 119 {
  120. 120 num++;
  121. 121 }
  122. 122
  123. 123 showMessage("谢谢参与,您一共选择了"+num+"项");
  124. 124
  125. 125 }
  126. 126
  127. 127 });
  128. 128 }
  129. 129
  130. 130
  131. 131
  132. 132 public void showMessage(String str)
  133. 133 {
  134. 134 Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
  135. 135 toast.setGravity(Gravity.TOP, 0, 220);
  136. 136 toast.show();
  137. 137 }
  138. 138 }
  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 android:orientation="vertical"
  4. 4 android:layout_width="fill_parent"
  5. 5 android:layout_height="fill_parent"
  6. 6 >
  7. 7 <TextView
  8. 8 android:layout_width="fill_parent"
  9. 9 android:layout_height="wrap_content"
  10. 10 android:text="你喜欢哪些智能手机系统"
  11. 11 />
  12. 12 <CheckBox
  13. 13 android:id="@+id/check1"
  14. 14 android:layout_width="fill_parent"
  15. 15 android:layout_height="wrap_content"
  16. 16 android:text="苹果 ios"
  17. 17 />
  18. 18 <CheckBox
  19. 19 android:id="@+id/check2"
  20. 20 android:layout_width="fill_parent"
  21. 21 android:layout_height="wrap_content"
  22. 22 android:text="谷歌 Android"
  23. 23 />
  24. 24 <CheckBox
  25. 25 android:id="@+id/check3"
  26. 26 android:layout_width="fill_parent"
  27. 27 android:layout_height="wrap_content"
  28. 28 android:text="RIM BlackBerry"
  29. 29 />
  30. 30 <CheckBox
  31. 31 android:id="@+id/check4"
  32. 32 android:layout_width="fill_parent"
  33. 33 android:layout_height="wrap_content"
  34. 34 android:text="微软 Windows phone 7"
  35. 35 />
  36. 36 <CheckBox
  37. 37 android:id="@+id/check5"
  38. 38 android:layout_width="fill_parent"
  39. 39 android:layout_height="wrap_content"
  40. 40 android:text="诺基亚 symbian"
  41. 41 />
  42. 42 <Button
  43. 43 android:id="@+id/mybutton"
  44. 44 android:layout_width="fill_parent"
  45. 45 android:layout_height="wrap_content"
  46. 46 android:text="确定"
  47. 47 />
  48. 48
  49. 49 </LinearLayout>

运行结果:


 

第四个例子:Spinner下拉菜单的事件处理

  1. 1 package org.hualang.eventtest5;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.os.Bundle;
  5. 5 import android.view.View;
  6. 6 import android.widget.AdapterView;
  7. 7 import android.widget.ArrayAdapter;
  8. 8 import android.widget.Spinner;
  9. 9 import android.widget.TextView;
  10. 10
  11. 11 public class EventTest5 extends Activity {
  12. 12 /** Called when the activity is first created. */
  13. 13 private static final String[] citys={"杭州","北京","成都","大连","深圳","南京"};
  14. 14 private TextView text;
  15. 15 private Spinner spinner;
  16. 16 private ArrayAdapter<String> adapter;
  17. 17 @Override
  18. 18 public void onCreate(Bundle savedInstanceState) {
  19. 19 super.onCreate(savedInstanceState);
  20. 20 setContentView(R.layout.main);
  21. 21 text=(TextView)findViewById(R.id.text);
  22. 22 spinner=(Spinner)findViewById(R.id.spinner);
  23. 23
  24. 24 //将可选内容与ArrayAdapter连接
  25. 25 adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,citys);
  26. 26 //设置下拉列表风格
  27. 27 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  28. 28 //将adapter添加到spinner中
  29. 29 spinner.setAdapter(adapter);
  30. 30 //添加Spinner事件监听
  31. 31 spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener()
  32. 32 {
  33. 33
  34. 34 @Override
  35. 35 public void onItemSelected(AdapterView<?> arg0, View arg1,
  36. 36 int arg2, long arg3) {
  37. 37 // TODO Auto-generated method stub
  38. 38 text.setText("你所在的城市是:"+citys[arg2]);
  39. 39 //设置显示当前选择的项
  40. 40 arg0.setVisibility(View.VISIBLE);
  41. 41 }
  42. 42
  43. 43 @Override
  44. 44 public void onNothingSelected(AdapterView<?> arg0) {
  45. 45 // TODO Auto-generated method stub
  46. 46
  47. 47 }
  48. 48
  49. 49 });
  50. 50 }
  51. 51 }

main.xml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 android:orientation="vertical"
  4. 4 android:layout_width="fill_parent"
  5. 5 android:layout_height="fill_parent"
  6. 6 >
  7. 7 <TextView
  8. 8 android:id="@+id/text"
  9. 9 android:layout_width="fill_parent"
  10. 10 android:layout_height="wrap_content"
  11. 11 android:text="您所在的城市"
  12. 12 />
  13. 13 <Spinner
  14. 14 android:id="@+id/spinner"
  15. 15 android:layout_width="wrap_content"
  16. 16 android:layout_height="wrap_content"
  17. 17 android:layout_centerHorizontal="true"
  18. 18 />
  19. 19 </LinearLayout>

运行结果如下:


 

 

 

第五个例子:Menu(菜单)的事件处理

  1. 1 package org.hualang.eventtest6;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.os.Bundle;
  5. 5 import android.view.Menu;
  6. 6 import android.view.MenuInflater;
  7. 7 import android.view.MenuItem;
  8. 8 import android.widget.Toast;
  9. 9
  10. 10 public class EventTest6 extends Activity {
  11. 11 /** Called when the activity is first created. */
  12. 12 @Override
  13. 13 public void onCreate(Bundle savedInstanceState) {
  14. 14 super.onCreate(savedInstanceState);
  15. 15 setContentView(R.layout.main);
  16. 16 }
  17. 17
  18. 18 @Override
  19. 19 public boolean onCreateOptionsMenu(Menu menu) {
  20. 20 // TODO Auto-generated method stub
  21. 21 MenuInflater inflater = getMenuInflater();
  22. 22 //设置menu界面为res/menu/menu.xml
  23. 23 inflater.inflate(R.menu.menu, menu);
  24. 24 return true;
  25. 25 }
  26. 26
  27. 27 @Override
  28. 28 public boolean onMenuItemSelected(int featureId, MenuItem item) {
  29. 29 //得到当前选中的MenuItem的ID
  30. 30 int itemId = item.getItemId();
  31. 31 switch(itemId)
  32. 32 {
  33. 33 case R.id.apple:
  34. 34 Toast toast = Toast.makeText(this, "这是苹果", Toast.LENGTH_SHORT);
  35. 35 toast.show();
  36. 36 break;
  37. 37 case R.id.banana:
  38. 38 Toast toast2 = Toast.makeText(this, "这是香蕉", Toast.LENGTH_SHORT);
  39. 39 toast2.show();
  40. 40 break;
  41. 41 case R.id.exit:
  42. 42 EventTest6.this.finish();
  43. 43 break;
  44. 44 }
  45. 45 return true;
  46. 46 }
  47. 47
  48. 48
  49. 49 }

res/menu/menu.xml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <menu xmlns:android="http://schemas.android.com/apk/res/android">
  3. 3 <item android:id="@+id/apple"
  4. 4 android:title="苹果"
  5. 5 />
  6. 6 <item android:id="@+id/banana"
  7. 7 android:title="香蕉"
  8. 8 />
  9. 9 <item android:id="@+id/exit"
  10. 10 android:title="退出"
  11. 11 />
  12. 12 </menu>

运行结果如下:


 

第六个例子:对话框的事件处理

  1. 1 package org.hualang.dialog;
  2. 2
  3. 3 import android.app.Activity;
  4. 4 import android.app.AlertDialog;
  5. 5 import android.app.Dialog;
  6. 6 import android.app.ProgressDialog;
  7. 7 import android.content.DialogInterface;
  8. 8 import android.content.DialogInterface.OnClickListener;
  9. 9 import android.os.Bundle;
  10. 10 import android.view.LayoutInflater;
  11. 11 import android.view.View;
  12. 12
  13. 13 public class MainActivity extends Activity {
  14. 14 /** Called when the activity is first created. */
  15. 15 ProgressDialog myDialog;
  16. 16 @Override
  17. 17 public void onCreate(Bundle savedInstanceState) {
  18. 18 super.onCreate(savedInstanceState);
  19. 19 setContentView(R.layout.main);
  20. 20
  21. 21 Dialog dialog = new AlertDialog.Builder(MainActivity.this)
  22. 22 .setTitle("登录提示")
  23. 23 .setMessage("这里需要登录")
  24. 24 .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  25. 25
  26. 26 @Override
  27. 27 public void onClick(DialogInterface dialog, int which) {
  28. 28 // TODO Auto-generated method stub
  29. 29 LayoutInflater factory = LayoutInflater.from(MainActivity.this);
  30. 30 final View DialogView = factory.inflate(R.layout.dialog, null);
  31. 31 AlertDialog dlg = new AlertDialog.Builder(MainActivity.this)
  32. 32 .setTitle("登录框")
  33. 33 .setView(DialogView)
  34. 34 .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  35. 35
  36. 36 @Override
  37. 37 public void onClick(DialogInterface dialog, int whichButton) {
  38. 38 // TODO Auto-generated method stub
  39. 39 myDialog = ProgressDialog.show(MainActivity.this, "请等待...", "正在为你登录", true);
  40. 40 new Thread()
  41. 41 {
  42. 42 public void run()
  43. 43 {
  44. 44 try
  45. 45 {
  46. 46 sleep(3000);
  47. 47 }catch(Exception e)
  48. 48 {
  49. 49 e.printStackTrace();
  50. 50 }finally
  51. 51 {
  52. 52 myDialog.dismiss();
  53. 53 }
  54. 54 }
  55. 55 }.start();
  56. 56 }
  57. 57 }).setNegativeButton("取消",
  58. 58 new DialogInterface.OnClickListener() {
  59. 59
  60. 60 @Override
  61. 61 public void onClick(DialogInterface dialog, int which) {
  62. 62 // TODO Auto-generated method stub
  63. 63 MainActivity.this.finish();
  64. 64 }
  65. 65 }).create();
  66. 66 dlg.show();
  67. 67 }
  68. 68 }).setNeutralButton("退出", new DialogInterface.OnClickListener() {
  69. 69
  70. 70 @Override
  71. 71 public void onClick(DialogInterface dialog, int which) {
  72. 72 // TODO Auto-generated method stub
  73. 73 MainActivity.this.finish();
  74. 74 }
  75. 75 }).create();
  76. 76 dialog.show();
  77. 77
  78. 78 }
  79. 79 }

res/layout/dialog.xml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 android:orientation="vertical"
  4. 4 android:layout_width="fill_parent"
  5. 5 android:layout_height="fill_parent"
  6. 6 >
  7. 7 <TextView
  8. 8 android:id="@+id/username"
  9. 9 android:layout_width="wrap_content"
  10. 10 android:layout_height="wrap_content"
  11. 11 android:layout_marginLeft="20dip"
  12. 12 android:layout_marginRight="20dip"
  13. 13 android:text="账号"
  14. 14 android:gravity="left"
  15. 15 android:textAppearance="?android:attr/textAppearanceMedium"
  16. 16 />
  17. 17 <EditText
  18. 18 android:id="@+id/myusername"
  19. 19 android:layout_height="wrap_content"
  20. 20 android:layout_width="fill_parent"
  21. 21 android:layout_marginLeft="20dip"
  22. 22 android:layout_marginRight="20dip"
  23. 23 android:scrollHorizontally="true"
  24. 24 android:autoText="false"
  25. 25 android:capitalize="none"
  26. 26 android:gravity="fill_horizontal"
  27. 27 android:textAppearance="?android:attr/textAppearanceMedium"
  28. 28 />
  29. 29 <TextView
  30. 30 android:id="@+id/password"
  31. 31 android:layout_width="fill_parent"
  32. 32 android:layout_height="wrap_content"
  33. 33 android:layout_marginLeft="20dip"
  34. 34 android:layout_marginRight="20dip"
  35. 35 android:text="密码"
  36. 36 android:gravity="left"
  37. 37 android:textAppearance="?android:attr/textAppearanceMedium"
  38. 38 />
  39. 39 <EditText
  40. 40 android:id="@+id/mypassword"
  41. 41 android:layout_width="fill_parent"
  42. 42 android:layout_height="wrap_content"
  43. 43 android:layout_marginLeft="20dip"
  44. 44 android:layout_marginRight="20dip"
  45. 45 android:scrollHorizontally="true"
  46. 46 android:autoText="false"
  47. 47 android:capitalize="none"
  48. 48 android:gravity="fill_horizontal"
  49. 49 android:password="true"
  50. 50 />
  51. 51 </LinearLayout>

运行结果:


 

 

转自:http://www.iteye.com/topic/1060815

玩转Android---事件监听篇---第2篇的更多相关文章

  1. Android 事件监听处理

    事件监听的处理模型包括三个成员:事件源.事件以及事件监听器. 基于监听的事件处理模型一般包括几个步骤: 1.获取普通界面组件: 2.实现事件监听器类 3.将监听器对象注冊给普通组件 当事件源上发生指定 ...

  2. Android事件监听(二)——点击鼠标事件

    Button.ImageButton事件监听(setOnClickListener) 方法一:通过匿名内部类实现 代码如下: package com.note.demo2; import androi ...

  3. android 事件监听

    步骤: 1.获取代表控件对象. 2.定义一个类,实现监听接口. 3.生成监听器对象. 4.为控件绑定监听器对象. XML <LinearLayout xmlns:android="ht ...

  4. 王立平--android事件监听的3种方式

    第一种通常在activity组件的oncreate事件中直接定义,直接动作. 这样的方式每一个控件都定义一次.通常不方便. Button btn = (Button) findViewById(R.i ...

  5. Android事件监听(一)——简介篇

    Button.ImageButton事件 setOnClickListener     点击时触发 ListView事件 setOnItemSelectedListener   鼠标滚动时触发 set ...

  6. Android如何监听蓝牙耳机的按键事件

    写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的 ...

  7. Android如何监听蓝牙耳机的按键事件(转)

    源: Android如何监听蓝牙耳机的按键事件 写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「 ...

  8. Android实现监听控件点击事件

    Android实现监听控件点击事件 引言 这篇文章主要想写一下Android实现监听点击事件的几种方法,Activity和Fragment实现起来有些方法上会有些不同,这里也略做介绍. 最近一直在忙一 ...

  9. Android怎样监听蓝牙耳机的按键事件

    Android怎样监听蓝牙耳机的按键事件 写在前面: 直接想要代码非常easy,你直接把滚动栏拉到最底端就能够看到.假设想要十分地了解为什么,那就依照我规划的一步一步来理解.下面測试环境以手头上有的「 ...

随机推荐

  1. Swift Strings and Characters

    String 是一个有序的字符集合,例如 "hello, world", "albatross".Swift 字符串通过 String 类型来表示,也可以表示为 ...

  2. zabbix windows angent安装:

    zabbix windows angent安装:1.下载zabbix agent for windows客户端,直接解压到C盘下.C:\zabbix 的目录015/04/21 11:16 <DI ...

  3. stagefright框架(七)-Audio和Video的同步

    讲完了audio和video的处理流程,接下来要看的是audio和video同步化(synchronization)的问题.OpenCORE的做法是设置一个主clock,而audio和video就分别 ...

  4. Letter of inquiry about employment possibilities, e-mail version

    Subject: (logical to recipient!) Inquiry about software engineering position after completion of M.S ...

  5. mysql 取得行号后再排序

    一.理论准备 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等. TreeMap:基于红黑树(Red-Black tre ...

  6. jeasyui制作计划-搭建php运行环境

    1.参考链接: http://jingyan.baidu.com/article/154b46315242b328ca8f4101.html http://jingyan.baidu.com/arti ...

  7. 正确合理的建立MYSQL数据库索引

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将对整 ...

  8. ZendStudio10 代码格式化 xml

    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <profi ...

  9. ORACLE 绑定变量用法总结 .

    之前对ORACLE中的变量一直没个太清楚的认识,比如说使用:.&.&&.DEIFINE.VARIABLE……等等.今天正好闲下来,上网搜了搜相关的文章,汇总了一下,贴在这里,方 ...

  10. 正三角形的外接圆面积,nyoj-274

    正三角形的外接圆面积 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 描述给你正三角形的边长,pi=3.1415926 ,求正三角形的外接圆面积.   输入 只有一组测试数据 ...