Android Learning notes • Start from scratch "one"

Source: Internet
Author: User

Get started with Android. like most people who start with eclipse, they are a bit of a muddle.

Before looking at the cocos2d, Cocos2d was later delayed, about Cocos2d Point this crossing , later update notes.

Now do the Android learning notes , recording drip.

-Click to go to the Android learning note map.

- 19 Android Classic Tutorials + 104 hot items on GitHub open stream

Come on!

1 Binding SDK Toolkit HTTP://DEVELOPER.ANDROID.COM/SDK

2 Application Name: Display names after installation; project name: item names (usually with no spaces); Package Name: Pack name (such as Com.cleopard.testhello).

3 Window→open Perspective→ddms; the tools you need to develop Android, you can now view the status of the device you want to see in the Devices window (drop the line and reset it with reset adb).

4 Assets Folders , which can be read dynamically while the program is running, or webview load local Web pages for storage.

5 Android does not recommend hard-coding strings in a program, and a better practice is to define strings in Res/values/strings.xml, which can then be referenced in layout files or code.

1. In the code, use the R.string.hello_world reference.

2. In XML, refer to by @string/hello_world.

6 Log Tool Logcat

Add Logcat to Eclipse:window->showview->other (expand Android)

1.LOG.V ()

This method is used to print the most trivial, least meaningful log information. The corresponding level verbose is the lowest level in the Android log.

2.LOG.D ()

This method is used to print some debugging information that should be helpful for debugging your program and analyzing the problem. The corresponding level of debug, higher than the verbose level.

3.log.i ()

This method is used to print some of the more important data that you would like to see that can help you analyze user behavior. corresponding level info, higher than Debug.

4.LOG.W ()

This method is used to print some warning messages, suggesting that the program may have potential risks in this place, and it is best to fix these warnings. Corresponds to level warn, one level higher than info.

5.LOG.E ()

This method is used to print error messages in a program, such as a program entering a catch statement. When the error message is printed, it usually means that your program has a serious problem and must be repaired as soon as possible. The corresponding level of error, higher than the warn level.

7 Ctrl+shift+o Import packages automatically , such as import android.util.Log;

8 It is highly recommended that irrelevant items be closed and only the items needed for the current job will be opened, otherwise I promise you will suffer in this regard. Right-click Projects->close Project.

9 input prompt, auto complete . Other similarities.

Open the Content Assist, Editor-and-perferences->, Windows, Eclipse, Window, and find auto-acti in the bottom right column Vation, here are three options to find the second "Auto activation triggers for Java:" option

you'll see a "." In the text box that follows. Exist. This means: only enter "." Then there will be code hints and auto-completion, and the place we want to modify is here. Put the "." In the text box Replace it with "abcdefghijklmnopqrstuvwxyz." So you can write Java code in Eclipse and press "ABCDEFGHIJKLMNOPQRSTUVWXYZ." Any one of the characters in the box will have code hints.

Create activity , etc. manually.

1. Right-click Src->new->package.

2. Right-click the new package->new->class. (Inherit activity, rewrite OnCreate ())

3. Create the appropriate layout: Right-click Res/layout->new->androidxml File; (default linearlayout)

4. Load the layout of the activity: return activity in the OnCreate () method to add Layout,setcontentview (r.layout.first_layout);

Note 1. Auto-complete, Android SDK will automatically provide an Android package under the R file, do not use the wrong !

NOTE 2. Register the startup page in Androidmanifest.xml

Note 3. The label specified for the main activity will not only become the content in the picky bar, but will also be the name displayed by the application in the Launcher (Launcher).

One Hide title bar :

in the OnCreate function, add requestwindowsfeature (Window.feature_no_title) before Setcontentview ();.

A method specifies an error or ambiguity?


The Onclicklistener () method specifies the error, just like the R above, it should be.

Two solutions:

1.new Onclicklistener () instead of->new Button.onclicklistener ()

2. Add->import Android.view.View.OnClickListener at the top of the page;

It seems to be getting familiar with Eclipse's environment and style ....


Click "Import ' Onclicklistener ' (Android.view.View)".

Summary:

1. After encountering the error, first put the mouse up to see.

2. You can put the cursor as to the error, with the shortcut key ctrl+1.

3. Use Ctrl+shift+o to add the package globally, used before.

- Toast (reminder, automatically disappears after message is displayed)

can be written to the button click event [OnClick ()] in: Toast. Maketext (Firstactivity. This, the "you click button", Toast. length_short). Show ();

using the static method Maketext () in a toast, you can "point out" directly. Three parameters [Context, content, duration of display]

- Menus (menu)

1. First in the Res directory resume a menu folder (right-Res->new->folder), and then add a Androidxml File under the menu directory.

2. Open Menu.xml and Add Item:

            <item  android:id= "@+id/add_item"  android:title= "add"/> <item android:id=            "@+id/remove_item"  android:title= "Remove"/>
        3. Rewrite the Oncreateoptionsmenu () method in the activity:

            @Override public            Booleanoncreateoptionsmenu (Menu menu)            {                getmenuinflater (). Inflate (R.menu.menu,menu) ;//Use to inflate, see                return True below;            }
        4. Add a menu response event, and then override the Onoptionsitemselected () method in activity:

            @Override public            booleanonoptionsitemselected (MenuItem item) {                switch (Item.getitemid ()) {case                    R.id.add _item:                    Toast.maketext (This, "add", Toast.length_short). Show ();                    break;                    Case R.id.remove_item:                    toast.maketext (This, "remove", Toast.length_short). Show ();                    break;                    Default: Break                    ;                }                return true;            }

Here's a toast pop-up message, don't forget to write the last. Show ().

5. The system comes with a menu key to activate, Meizu does not, so can not play.

the about inflate ()

in layman's words, inflate is the equivalent of locating a layout defined in an XML.

in an activity, if you use Findviewbyid () directly, the corresponding component in the layout of Setconentview ().

So if you use other layout in your activity, such as the layout on the dialog, you also have to set the contents of the Layout on the dialog box (like picture ImageView, text TextView), You have to use inflate () to find the layout of the dialog box first, and then use the layout object to find the components above it, such as:

<pre name= "code" class= "java" >            View view1=view.inflate (this,r.layout.dialog_layout,null);            TextView dialogtv= (TextView) View1.findviewbyid (R.ID.DIALOG_TV);            Dialogtv.settext ("ABCD");

Note: R.ID.DIALOG_TV is a component on the layout of the dialog box, and if the direct use of This.findviewbyid (R.ID.DIALOG_TV) will definitely be an error.

- Destroying Activity

the Activity class provides a finish () method that calls this method in an activity to destroy the current activity.

        Button1.setonclicklistener (Newonclicklistener () {            @Override            publicovid OnClick (View v) {                finish ();            }        } );

The effect is the same as pressing the back key.

You have any questions to ask me, a little, I am also a novice. Come on!

····················································································

· This is the end of today 2015/03/03 13:20 Cleopard

····················································································

Android Learning notes • Start from scratch "one"

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.