You can either directly drag different buttons, text views etc. in graphical layout or you can write the code in xml file. Let’s try to understand the bit of the code-
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
Here, ‘TextView’ is an area in our layout, used to show any text. layout_widthandlayout_height are defined as “wrap_content” it means that it wrap the text view and take space or area of the text. See the example:
“android:text” shows the text or string in the textview.“@string/hello_world”refers to string available in values folder with id as ‘hello_world’. To change the string from“Hello world” to another replace android:text=”@string/hello_world”to this:
android:text=”your name”
7. Go to File-->save all.
STEP 2- RUNNING YOUR ANDROID PROJECT
METHOD#1: RUNNING ANDROID APPLICATION ON EMULATOR
To run your project in an emulator you first need to create the virtual device first. Follow the steps to create a virtual device:
1. Go to Window-->Android Virtual Device Manager.
2. Create a new AVD by clicking new.
3. Enter the AVD name, Select Device, Target as shown in screenshot.
4. Your virtual device is created, To run your code go to your folder name right click on it, then Run As-->Android application.
5. Now you can see the virtual device running and application will automatically run on the virtual device.
METHOD#2: RUNNING ANDROID APPLICATION ON ACTIVE DEVICES (ON YOUR ANDROID MOBILE)
To run the source code as application on your mobile follow these steps:
1. In your mobile go to Settings-->Applications-->Development. Check the USB debugging. 2. Connect your mobile with your System using USB cable.3. Right click on your project folder then Run As-->Run Configurations.4. Go to ‘target’ tab, check ‘Launch on all compatible devices/AVD’s5. Click apply and run.6. Application will run in your android mobile.
Guys, that’s it for today, now you have the basics knowledge of the files used in an android application. You learned what is package, what are classes, what are methods, what is XML file etc. You also learned to run the application in virtual device and in your android mobile as well.
In our next tutorial we will learn more about the XML. We will learn to design few screens, learn to include media files such as audio, images etc. we will create the form screen and much more. Hope you understood the tutorial very well, In case you get any difficulty leave your comment.