Wheat Android Development Tutorial: Android Development Framework Detailed

Source: Internet
Author: User

There are a lot of students in the wheat academy who are beginning to develop Android to ask the Android development Framework, followed by the Wheat Academy's Android teacher to see the relevant code:

Java code

1. Publicclass App extends Activity {2.3. Public App () {//constructor needless to say4.}5.6. public void OnCreate (Bundle savedinstancestate) {//The interface is initialized when called7. Super.oncreate (savedinstancestate);8.9. Setcontentview (r.layout.skeleton_activity);//Display layout interface, XML is defined, refers to the advanced interface. .//setcontentview (New MyView (this));//Display layout interface, refers to the low-level interface, MyView it is an internal class, followed by the introduction. .13.//The following is the initialization of other data. .......}.Public Boolean Oncreateoptionsmenu (Menu menu) {//Initialize menu menu selectionsuper.oncreateoptionsmenu (menu);.22.//Add menu items, such as:.menu.add (0, ok_id, 0,r.string.ok). Setshortcut (' 2 ', ' V ');//Set shortcut keys25.//Add other menu items ... .. return true;.}.Public Boolean Onprepareoptionsmenu (Menu menu) {//super.onprepareoptionsmenu (menu);.33.//Here you can set the visibility of the menu beforehand, if it is visible, you can not set.Menu.finditem (ok_id). setvisible (true);//Set menu item Visibility. return true;Panax Notoginseng.}.onoptionsitemselected Public boolean (MenuItem item) {//Select a menu item to invoke.41.//The desired variable can be pre-processed hereswitch (Item.getitemid ()) {Case back_id://a deal to do what you want to do, don't let me introduce you .... return true;. It's a .......}.* . Return super.onoptionsitemselected (item);.}.54.//The following is an internal class myview, if you are using an advanced interface (based on XML), this class can not be, if it is a low-level interface, you say? .MyView public class extends View () {.MyView Public (CONTEXTC) {.A . Super (c);.62.//Initialize other things ..... ..}.protected voidonsizechanged (int w, int h, int oldw, int oldh) {//not commonly used, can not be written. super.onsizechanged (W, H, OLDW, OLDH);.}.protected Voidondraw (canvas canvas) {//almost must writecanvas.drawxxx ();..//invalidate ();//If you have animations, you must add them. .}The .booleanontouchevent Public (Motionevent event) {78.//do something before you touchswitch (event.getaction ()) {Case Motionevent.action_down:Bayi. Invalidate ();//If you want to animate or refresh, add this sentence; usually it seems to be added here;A . break;Case Motionevent.action_move:invalidate ();Break ;Case MOTIONEVENT.ACTION_UP:invalidate ();Break ;.}. return true;.}.}A .94.}

95.}

More Tutorial videos on Android development at: Http://www.maiziedu.com/course/android/

Wheat Android Development Tutorial: Android Development Framework Detailed

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.