Tuesday, November 19, 2013

My first Android app

To create an Android project:
  • go to File ---> New ---> Android Projec
  • Specify the project name: HelloWorld, and click Next 
  • Choose the Android platform to use (in this case 2.3.3), click Next
  • In the next window, you must specify a package to use, which must be unique. This package must contain at least two levels. In our case, you can type i.helloworld   
  • Click Finish. A new project appears. 
  •  tree of an Android project:  

  •  onCreate() :  This method is called to create an activity. It allows you to initialize. This is  where the graphical interface is specified.
  • onStart (): This method is called when the application is started.
  • onResume (): This method is called when the application passes (or returns) in the foreground.
  • onPause (): Called when the application moves to the background and another application goes ahead.
  • onStop (): Called when the application is no longer visible.
  • OnStart (): Called when the application becomes visible.
  •  onDestroy (): Called when your application is closed by the system due to a lack of resources, or by the user using a finish ().
 It is therefore possible to specify a behavior for each of these events. To do this, simply add the corresponding methods (in the same way as the onCreate method) already generated by ADT.



 Click on the method that is proposed. Its code will be automatically generated.

  1. Adding graphic elements :
The graphical interface is managed through xml files in the directory layout. ADT offers a friendly interface to manage these files and graphically manipulate the elements of the interface.
 
  • In the code file main.xml, associate a name and a title for your button:          
            <Button 
                   android: id = "@ + id / buttonDisplay" 
                   android: text = "Show" 
            ... />
 

It is possible to create all the elements of the interface through the drag-and-drop.

To set the behavior of your button, follow these steps: 

package i.HelloWorld;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class helloworldActivity extends Activity {
    /** Called when the activity is first created. */
  
/**Create an attribute in your activity type Button:**/
      private Button bDisplay;
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


     2.  Behavior of a button : 
  •  In the onCreate () method:
          - Initialize the attribute bAfficher by associating the button created in the main.xml:
                    this.bDisplay = (Button) this.findViewById ("buttonDisplay");
          - Attach a behavior to your button:
                    this.closeButton.setOnClickListener (OnClickListener new () {
                    public void onClick (View v) 

                    {
                         / / behavior of your button
                    }
                     });

HMAIDA.H

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

0 comments:

Post a Comment

 

Copyright @ 2013 ELECTRO DROID.

Designed by Atef.A | Deal Commerce