My Android Second lesson

Source: Internet
Author: User

Hey! Everybody, small make up again and everybody share knowledge, in yesterday's blog note Small-scale to everyone explained how to configure the Android tool and some configuration in the SDK, that in today's study small will bring you what Android knowledge? First, let's take a look at today's study catalogue.

Knowledge One: Understanding the Android project directory structure

Knowledge Two: Android configuration file (manifest file)

Knowledge Three: Understanding the role of DDMS

Knowledge Four: ADB executes commands and configurations

Knowledge Five: Simple case (call)

Directory structure for Android projects
    • Activity: The interface that is displayed when the app is opened
    • SRC: Project Code
    • R.java: The resource ID of all resource files in the project, which can be read by ID to the file information in layout under the file, equivalent to the resource pointer of the program
    • Android.jar:Android jar Package, import this package to use the Android API
    • Libs: Importing third-party jar packages
    • Assets: Storing resource files, for example MP3, video files
    • Bin: Store compiled and packaged files
    • Res: The resource file is stored and all resource files stored in this folder will generate the resource ID
    • Drawable: Storing picture resources
    • Layout: Store the layouts file, assign the layout file to the activity through the resource ID, and the interface will show the layout of the layout file definition.
    • Menu: Define the style of the menu
    • Strings.xml: Storing string resources, each resource will have a resource ID
Android configuration file (manifest file)
    • Specify the package name of the app

      package="com.itheima.helloworld"
      • Data/data/com.itheima.myfirstandroid (the package name specified in the code above)
      • The files generated by the app will be stored in this path
    • All four components of Android need to be configured in the manifest file before use

    • Configuration takes effect for the entire application
    • Configuration is in effect for this activity
DDMS
    • Dalvik Debug Monitor Service
    • Dalvik Debug Monitoring service: You can see your device connection information in the debug controller and which devices you have connected to

ADB execution Commands and configuration

Android Debug Bridge: Android Debugging Bridges: ADB is the connection between Eclipse and server devices, the ADB program can connect to any Android device, and the ADB program can also get all the information of your current connected device

We can quickly and easily use the following commands when we enable the ADB program

    • ADB start-server: Start adb process
    • ADB kill-server: Kill ADB process
    • ADB devices: View the devices currently connected to the development environment and this command can also start the ADB process
    • ADB install xxx.apk: Installing APK to Simulator
    • ADB Uninstall Package Name: Remove an app from the emulator
    • ADB shell: Enter the Linux command line
    • PS: View the running process
    • LS: View the file structure under the current directory
    • Netstat-ano: Viewing the process that occupies the port

Haha, some scholars have already encountered a problem, that is, when opening the DOM window to execute the command, how can not be executed?

ADB configuration

OK, the problem is solved, only need to configure the ADB environment variables can be

First open Control Panel--System and security--and advanced settings--environment variable-->path variable

Click Edit: First to find your SDK to store the Adb.exe file directory

Get the path to the directory

Note : Demo path: F:\AndroidStudy\adt-bundle-windows-x86_64-20140702\sdk\platform-tools

Then copy the path to the value of your PATH variable

Simple Case (call)

Function: The user enters a number, clicks the Dial button, starts the system to call the application to call out the number

1. Create a new Android project

2. Click the layout file in the Res directory to open the Activity_main.xml configuration file

3. Generate several controls, one: Text edit control, two: Button control

Activity_main.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity "android:orientation= "vertical"    >    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Please enter the phone number you want to dial" />        <EditTextAndroid:id= "@+id/edit_test"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"                />     <ButtonAndroid:id= "@+id/btn_cell"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Call"         /></LinearLayout>

Note 1: The component must be set to a wide height, otherwise it cannot be compiled

Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"

To make it easier for us to control the layout content, we changed <relativelayout ></relativelayout > in XML to <LinearLayout></LinearLayout>

The following is the control-generated

NOTE 2: If the corresponding control is generated manually, you must specify a control ID android:id= "@+id/textview1" or run an error

Android:id= "@+id/textview1"

  

4. Write our Java code

Click the Mainactivity.java file under SRC to write the following code

 Packagecom.example.myfirstandroid;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);       Setcontentview (R.layout.activity_main); //Gets a Btn_cell button objectButton btn = (button) This. Findviewbyid (R.id.btn_cell); //binds a button listener event to the button objectBtn.setonclicklistener (NewMyListener ()); }        //Write a listener inner class implement Onclicklistener listener interface    classMyListenerImplementsonclicklistener{@Override//Override the Click event method for this interface         Public voidOnClick (View v) {//get Edit Text ObjectEditText edittest =(EditText) Findviewbyid (r.id.edit_test); //get the contents of the edited textString number =Edittest.gettext (). toString (); //get a system built-in call function that tells the system we're going to do a call operation//get a Create Diagram objectIntent Intent =NewIntent (); //to encapsulate an action in a create diagramintent.setaction (Intent.action_call); //set the call to WHO to operateIntent.setdata (Uri.parse ("Tel:" +Number )); //This action is told to the system when the above execution is completestartactivity (Intent); }            }}

The above simple applet code has been written, run quickly try it!

Summary: Today's small series of Android knowledge points have been shared, today's learning content is only a general understanding of the basic structure of the Android program, the case also used the definition of internal classes, if you do not understand the internal class operation of the scholar can also refer to the small compilation of internal class learning notes may help you Oh! Address: http://www.cnblogs.com/xiaotaojing/p/6069184.html because the definition of internal classes is very common and often used in the development of Android, If there are some scholars on the comparison have not understood or have doubts about the place can give small message Oh! Thank you

My Android Second lesson

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.