1. In Android.view.KeyEvent, onkeydown represents the response to keyboard keys
Need to rewrite the onkeydown function
@Override
public boolean onKeyDown (int keycode, keyevent msg) {
There are four kinds of keyevent events keycode_dpad_up, Keycode_dpad_right, Keycode_dpad_left, Keycode_dpad_down.
2 in Android.view.motionEvent,. Ontouchevent indicates a response to the touchscreen
Need to rewrite the ontouchevent function
@Override
public boolean ontouchevent (Motionevent event) {
float x = Event.getx ();
Float y = event.gety ();
3. How to implement activity jumps
Intent Intent = new Intent (); Establish intent
Intent.setclass (Forwarding.this, Forwardtarget.class); Set up activities
StartActivity (Intent);
Finish (); End Current Activity--optional
4. Carry parameters in Activity01 jump to Activity02 for processing, and return the processing results to the implementation steps in ACTIVITY01
1.activity01 defined in the event specified in the
Intent Intent = new Intent (receiveresult.this, Sendresult.class);
Startactivityforresult (Intent, Get_code);
2.ACTIVITY02, the data that will be returned is encapsulated into setaction after processing.
Setresult (RESULT_OK, (New Intent ()). Setaction ("corky!"));
overriding Onactivityresult (int requestcode, int resultcode,intent data) events in 3.activity01
5. How to add menus and responses
1. Overriding the oncreateoptionsmenu(Menu menu) function
2. In the function, add menu.add (0,red_menu_id,0,r.string.red);
3. Overriding public boolean onoptionsitemselected(MenuItem Item)
4.swith (Item.getitemid ()) {
Case RED_MENU_ID:
Break
}
Abstract MenuItem Add (int groupId, int itemId, int order, charsequence title)
6. Pop-up dialog box
Android.app.AlertDialog to implement pop-up dialog boxes
Use Alertdialog.builder and different parameters to build the dialog box.
return new Alertdialog.builder (alertdialogsamples.this)//Returns a dialog box
. SetIcon (R.drawable.alert_dialog_icon)//Set icon
. Settitle (R.string.alert_dialog_two_buttons_title)//Set title
. Setpositivebutton (R.STRING.ALERT_DIALOG_OK, New Dialoginterface.onclicklistener () {
public void OnClick (dialoginterface dialog, int whichbutton) {
/* Left button event */
}
});
. Setneutralbutton (R.string.alert_dialog_something, New Dialoginterface.onclicklistener () {
public void OnClick (dialoginterface dialog, int whichbutton) {
/* Middle Key event */
}
})
. Setnegativebutton (R.string.alert_dialog_cancel, New Dialoginterface.onclicklistener () {
public void OnClick (dialoginterface dialog, int whichbutton) {
/* Right-click event */
}
})
. Setmessage (R.STRING.ALERT_DIALOG_TWO_BUTTONS2_MSG)//Set message content
. Setitems (R.array.select_dialog_items, New Dialoginterface.onclicklistener () {//List Item dialog box
public void OnClick (Dialoginterface dialog, int which) {
string[] Items =getresources (). Getstringarray (R.array.select_dialog_items);
New Alertdialog.builder (Alertdialogsamples.this)
. Setmessage ("You selected:" + which + "," + Items[which])
. Show ();
}
})
. Setsinglechoiceitems (R.ARRAY.SELECT_DIALOG_ITEMS2, 0, New Dialoginterface.onclicklistener () {//Single Option and Button dialog box
public void OnClick (dialoginterface dialog, int whichbutton) {
}
})
. Setmultichoiceitems (R.ARRAY.SELECT_DIALOG_ITEMS3,
New Boolean[]{false, True, False, True, False, False, false},
New Dialoginterface.onmultichoiceclicklistener () {
public void OnClick (dialoginterface dialog, int whichbutton,boolean isChecked) {//Multiple Options and Buttons dialog box
/* Click the response of the check box */
}
})
Article cited from the blog park: http://www.cnblogs.com/oftenlin/archive/2013/03/27/2984674.html
Various events and pop-up windows for Android development