The next day I learned about Android development. The goal is to participate in the Google Android competition and win a prize. However, the reward is small and the accumulated development experience is large, you can also find a good job on the day you are looking for a job ~~
Today's learning content: helloworld mainly involves the feeling that an activity is a window. Every time you create an activity, register it in androidmanifest. xml.
Android resources all record this in res. For example, the string in the values directory can be defined.ProgramAll the strings used in layout define all the UIS and implement the MVC mode.
To reference these resources, use the r class as a bridge to access these resources, such as setcontentview (R. layout. Main );
If you want to use the resource defined in layout, for example, a button, you can edit the ID of this UI part in the UI editing window, and then reference this part through ID in the main program.
For example, we define a button in main layout and edit its ID as button1. At this time, button1 will automatically generate a member in this ID in the r class, the name is the same as button1. We can reference this button1 to reference this resource.
CodeButton button = (button) findviewbyid (R. Id. button2 );
Then, you can perform logical editing on the button, for example, adding the corresponding function:
Button. setonclicklistener (New button. onclicklistener () {public void onclick (view v) {/* Create an intent object */intent = new intent ();/* specify the intent class */intent. setclass (activity01.this, activity02.class);/* start a new activity */startactivity (intent);/* close the current activity */activity01.this. finish ();}});
This part of the code calls the button to add the click Response Function
The intent is used to call a function to switch from one activity to another. Implement similar interface switching
Example 3 shows how to access the address book. The address book access method changes with different versions. In practice, the number field is no longer available. The following code can obtain the phone number and user
Contentresolver Cr = getcontentresolver (); // obtain the cursor = CR for the first entry in the phone book. query (contactscontract. contacts. content_uri, null, null); // move the cursor down while (cursor. movetonext () {// get the contact name int namefieldcolumnindex = cursor. getcolumnindex (contactscontract. contacts. display_name); string contact = cursor. getstring (namefieldcolumnindex); string contactid = cursor. getstring (cursor. getcolumnindex (phonelookup. _ id); cursor phone = CR. query (contactscontract. commondatakinds. phone. content_uri, null, contactscontract. commondatakinds. phone. contact_id + "=" + contactid, null, null); While (phone. movetonext () {int phonefieldcolumnindex = phone. getcolumnindex (contactscontract. commondatakinds. phone. number); string phonenumber = phone. getstring (phonefieldcolumnindex); string + = Contact + ":" + phonenumber + "\ n ";}
Phone. close (); // string + = (contact + ":" + number + "\ n");} cursor. close (); // set the content displayed in textview to TV. settext (string );