Tips on Android keyboard operations

Source: Internet
Author: User

Friends who know something about mobile phones may know that the Android operating system is an important system in this field. Next we can give a preliminary understanding of the application methods and functions of this system through the introduction of Android keyboard operations.

  • Analysis of Android Menu Programming Method
  • Analysis of Android resource application skills
  • Android ListView complex usage
  • Android uses XML-related skills
  • Analysis of Android progress bar related application skills

In Android, the program is operated through the touch screen and keyboard. How do we respond to General keyboard and touch pen actions? Through understanding the operations on some basic interface elements of Android, if you are familiar with MVC, you can guess how Android handles Keyboard Events. Congratulations, you guessed it, change the Event Response Function in the Activity.

It is generally the following three functions for Android keyboard operation:

OnKeyDown, onKeyUp, on, onKeyMultiple

See the following Android keyboard operation code:

 
 
  1. import android.app.Activity;  
  2. import android.app.ProgressDialog;  
  3. import android.os.Bundle;  
  4. import android.view.KeyEvent;  
  5. import android.view.Menu;  
  6. import android.view.MenuItem;  
  7. import android.widget.TextView;  
  8. public class TestProgress extends Activity {  
  9. private ProgressDialog progress = null;  
  10. @Override  
  11. public void onCreate(Bundle savedInstanceState) {  
  12. super.onCreate(savedInstanceState);  
  13. setContentView(R.layout.main);  
  14. }  
  15. @Override  
  16. public boolean onCreateOptionsMenu(Menu menu) {  
  17. super.onCreateOptionsMenu(menu);  
  18. menu.add(0, Menu.FIRST+1, 1, "Open Progress");  
  19. menu.add(0, Menu.FIRST+2, 2, "Exit");  
  20. return true;  
  21. }  
  22. @Override  
  23. public boolean onOptionsItemSelected(MenuItem item) {  
  24. super.onOptionsItemSelected(item);  
  25. switch (item.getItemId())  
  26. {  
  27. case Menu.FIRST +1:  
  28. {  
  29. progress = new ProgressDialog(this);  
  30. progress.setTitle("Progress!!");  
  31. progress.setMessage("Please wait for the operation...");  
  32. progress.setCancelable(true);   
  33. progress.show();  
  34. //progress = ProgressDialog.show(this, "Progress!", 
    "Please wait for operation...");  
  35. break;  
  36. }  
  37. case Menu.FIRST +2:  
  38. {   
  39. finish();  
  40. break;  
  41. }  
  42. }  
  43. return true;  
  44. }  
  45. @Override  
  46. public boolean onKeyDown(int keyCode, KeyEvent event) {  
  47. // TODO Auto-generated method stub  
  48. super.onKeyDown(keyCode, event);  
  49. setTitle("you pressed key:" + String.valueOf(keyCode));  
  50. return true;  
  51. }  
  52. @Override  
  53. public boolean onKeyMultiple(int keyCode, int repeatCount, 
    KeyEvent event) {  
  54. // TODO Auto-generated method stub  
  55. super.onKeyMultiple(keyCode, repeatCount, event);  
  56. TextView tv = (TextView)this.findViewById(R.id.mainview);  
  57. tv.setText("you have press key:[" + String.valueOf(keyCode) + "] 
    for:" + String.valueOf(repeatCount) + "Times!");  
  58. return true;  
  59. }  
  60. @Override  
  61. public boolean onKeyUp(int keyCode, KeyEvent event) {  
  62. // TODO Auto-generated method stub  
  63. super.onKeyUp(keyCode, event);  
  64. setTitle("you release key:" + String.valueOf(keyCode));  
  65. return true;  
  66. }  

The Android keyboard operation application is introduced here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.