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:
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.TextView;
- public class TestProgress extends Activity {
- private ProgressDialog progress = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- menu.add(0, Menu.FIRST+1, 1, "Open Progress");
- menu.add(0, Menu.FIRST+2, 2, "Exit");
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- super.onOptionsItemSelected(item);
- switch (item.getItemId())
- {
- case Menu.FIRST +1:
- {
- progress = new ProgressDialog(this);
- progress.setTitle("Progress!!");
- progress.setMessage("Please wait for the operation...");
- progress.setCancelable(true);
- progress.show();
- //progress = ProgressDialog.show(this, "Progress!",
"Please wait for operation...");
- break;
- }
- case Menu.FIRST +2:
- {
- finish();
- break;
- }
- }
- return true;
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- super.onKeyDown(keyCode, event);
- setTitle("you pressed key:" + String.valueOf(keyCode));
- return true;
- }
- @Override
- public boolean onKeyMultiple(int keyCode, int repeatCount,
KeyEvent event) {
- // TODO Auto-generated method stub
- super.onKeyMultiple(keyCode, repeatCount, event);
- TextView tv = (TextView)this.findViewById(R.id.mainview);
- tv.setText("you have press key:[" + String.valueOf(keyCode) + "]
for:" + String.valueOf(repeatCount) + "Times!");
- return true;
- }
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- super.onKeyUp(keyCode, event);
- setTitle("you release key:" + String.valueOf(keyCode));
- return true;
- }
- }
The Android keyboard operation application is introduced here.