A look at the Android App Development Starter Tutorial _android

Source: Internet
Author: User
Tags android sdk manager

Work has done mobile phone app project, front-end and Android or iOS programmers to complete the development of the entire project, the development process with the iOS program with basically no problem, and the Android various machines and ROM problems are many, It also gives me an interest in learning about Android and iOS program development. So I couldn't sleep one o'clock in the morning. wrote the first Android program Helloandroid,po out to share with others who also want to learn about Android development, so stupid Android development primer, a little development base should be able to read.

First, preparatory work

Mainly in my own development environment for example, download the installation JDK and the Android SDK, if you do not have the existing IDE, you can directly download the SDK complete package, which contains eclipse, if there is an IDE then you can scroll down to choose the use of the IDE EXISTING, Then install the SDK, if your SDK is not found in the installation of the JDK directory, you can add java_home variables in the system environment variables, path for your JDK directory, my IDE is IntelliJ idea, all installed to start configuring the IDE to increase SDK support.

First, open the Android SDK Manager to the Android 4.0 version of the installation is not installed, according to your personal situation, if you only want to use your own mobile phone test, then the same version of your system SDK packaging, download time is a bit long.



Then open the IDE to create a new project, idea is more intelligent, if you installed the SDK, the new project will appear in the Android application Module, select the right side of the project SDK is empty, click the New button, find the SDK directory to determine, The Drop-down list lists the various versions of the SDK that you have installed, select the version you want, and if this is the first time you set up, the IDE will remind you to set up the JDK first, and follow the instructions to find the JDK directory.



After you fill out the project name, select the USB Device and then complete the project build, and the IDE automatically generates the files and directories needed for the basic project.


Second, code writing

When you're ready, you can finally start writing our Hello Android, and before we start writing the code, we'll look at a few files:

Res/layout/main.xml app main form layout file, what your application looks like in this definition, there are design and text two modes

Res/values/strings.xml can be understood as a i18n file, which is used to hold various strings of program calls

Src/com/example/helloandroid/myactivity.java This is our main program class, and the functionality to be implemented is added to this file.

First, add a textview with ID Hellotextview to the application and a button,mail.xml code with an ID of Hellobutton as follows:

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<textview
Android:layout_width= "Fill_parent"
android:layout_height= "180DP"
android:text= "@string/default_message"
Android:id= "@+id/hellotextview" android:textcolor= "#00ff00" android:gravity= "center"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/button_send"
Android:id= "@+id/hellobutton" android:layout_gravity= "center"/>
</LinearLayout>

The code and controls use the following string definition:

Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "App_name" >helloandroid by hiwanz</string>
<string name= "Button_send" >say something</string>
<string name= "default_message" >click button below!</string>
<string name= "Interact_message" >you just clicked on the button!</string>
</resources>

The main program defines the button click to change the TextView display text, and pop-up toast prompt message, the code is as follows:
Copy Code code as follows:

Package com.example.helloandroid;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;
Import Android.widget.Toast;

public class MyActivity extends activity {
/**
* Called when the activity is the created.
*/
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Get Button Instance
Button hellobtn = (button) Findviewbyid (R.id.hellobutton);
Set the Listener button click event
Hellobtn.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Get TextView Instance
TextView Hellotv = (TextView) Findviewbyid (R.id.hellotextview);
The pop-up Toast prompt button was clicked
Toast.maketext (Myactivity.this, "clicked", Toast.length_short). Show ();
Read Strings.xml-defined interact_message information and write to TextView
Hellotv.settext (R.string.interact_message);
}
});
}

}

After the code is written, the computer through the USB cable to connect the mobile phone, mobile phone system settings in the developer option to open USB debugging, in the IDE direct point run can see the effect of the operation on the phone.

Apply Package

After application development is ready to be packaged and released, select Generate signed APK to package the application under the IDE's Build menu

In the Pop-up wizard dialog box, you need to specify the signature key, no key at first you can click Create new to create a new key for signing, fill in some of the fields required by the signature to generate the key file

To sign an application package using the generated key

After compiling, we will build our HELLOANDROID.APK application package in the designation APK path that we set up just now, then how to install the application should needless to say, our first Android app was born. App Development recommendation

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.