Slash Coding

  • Android Development
  • CSS
  • Subscribe
  • About Us
  • Contact Us
You are here: Home / Android Development / Learn the basic elements of Android Application Development

Learn the basic elements of Android Application Development

By Aneesh Bhatnagar

Android Application Development is a growing at a high pace. And in order to keep up with the programming world, it is always advised to keep learning new things as soon as they come. But remember that learning everything is not possible. You have to be selective on what you want to learn and master upon. If you choose to learn Android Application Development, you must master it using whichever way you find easy. You can develop android applications using various methods, but it is your choice which one to learn and master!

Without taking much of your time, I would like to introduce you to the second Android Application that you would make. If you have no experience in developing Android applications and the very basics of it, i suggest you to read these articles before proceeding further.

  • Getting Started with Android App Development : Get your Tools Ready
  • Set up an Android Virtual Device on Eclipse
  • Creating Your First Android Application

After you make yourselves aware with the basics of Android Application development and how to create  a new application and also how to run it on an Android Virtual Device, proceed under.

Basic Elements of An Android Application

In this section, I would like to tell you how to add some basic elements to an Android Application. These basic elements will include a Text View (an element where any text can be displayed), an Edit Text field (where an input from the user can be taken) and at last, a button (which can be clicked to do some action). We are going to develop an application that takes and input string from the user and displays it below the button. Let’s get started with this now.

  1. Open your project in Eclipse and open the “activity_main.xml” file from the layouts folder by double clicking on it. You should see some similar Graphical Layout.
    Android Layout View
  2. On the Left side, you will see the Palette menu. Under the “Form Widgets”, click and drag Large Text and Button one after the other on to the Application layout. Now arrange them like in the image below.
    Button and TextView in Android
  3. Now under the “Text Fields” in the Palette menu, click and drag Plain Text right above the button and now it should look like this.
    Android Application Layout
  4. Click on the button and on the right side, in the properties menu change the id to “@+id/submit” and when asked if you want to update references, update them at once. Next, change the Text filed in the Properties to “Submit Text”.
    Button Properties
  5. Next, click on the Large Text view we created and change the Text in the Properties Menu to anything you want. I changed it to “Text Displayed Here”.
  6. Now, click on the Edit Text field and here, enter the hint for the edit text in the properties menu again. I changed it to “Enter a string here”. This is how it should look right now. Save the file ( Ctrl + S).
    Final Layout of Android Application
  7. Now we are done with designing the User Interface. Now let us go into java and define the code for the thing we need done. Open the “MainActivity.java” file from src -> com.slashcoding.helloworld under the Hello World Project in the Project Explorer on the right.
    Layout Class in Java
  8. Now in the onCreate method, add the following lines of code. After you add these lines, press Ctrl + Shift + O to import the required classes into your java file. Basically by adding these lines of code, we are defining variables of Button, EditText and TextView classes to java and then referencing them with the elements in the XML file we created earlier.
    Button b = (Button) findViewById(R.id.submit);
    final EditText et = (EditText) findViewById(R.id.editText1);
    final TextView tv = (TextView) findViewById(R.id.textView1);
    
  9. Now, we will sent a on Click Listener for the button. This basically defines all the things we need to do when the button is clicked. Add this code to the onCreate function as well, just below the TextView definition.
    b.setOnClickListener(new View.OnClickListener() {
    
    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    tv.setText(et.getText().toString());
    }
    });
    

    In this code, we have defined an onClickListener for the button and asked it to set the text in our Text View to be equal to the text in the Edit Text field, which is entered by the user.

  10. That’s all. You are done. Now save this java file and run your application either on a physical Android Device or on an Android Virtual Device.  This is how your onCreate Function should look like now.
    onCreate Function Final
    Android Application Preview

Well, that’s all for now. This is a simple tutorial to understand the use of Edit Text, Button and a Text View. You can use these to create powerful applications that can do various things. I will come back to on your various applications that you can make by just using the things I described here and some common sense. Stay updated with all the new posts from Slash Coding right on your Facebook Wall, Twitter feed or in your Favorite RSS Reader. Also, if you face any problem, feel free to contact me using the contact page or commenting below!

Did you enjoy this article?
Subscribe to our email alerts when we post something new so you don't miss out.

About Aneesh Bhatnagar

Aneesh Bhatnagar is a freelance web developer, who specializes in front-end website development with HTML5, CSS3 and jQuery. He believes in transforming the entire web into a Responsive Web. He also specializes in use of Bootstrap framework to get websites up and running.

Comments

  1. Evie Marian says

    March 11, 2014 at 5:37 pm

    I am sure this article has touched all the internet viewers,
    its really really nice piece of writing on building up new application.

  2. Braxton says

    April 14, 2014 at 11:55 am

    I constantly spent my half an hour to read this weblog’s content every day along with a mug of
    coffee.

    • Aneesh Bhatnagar says

      April 14, 2014 at 10:58 pm

      Thank you for such a valuable feedback Braxton! 🙂

Trackbacks

  1. Learn how to use the Basic Elements of Android Applications - appgong says:
    June 12, 2014 at 9:58 am

    […] Learn how to use the Basic Elements of Android Applications […]

Search Slash Coding

Follow Us

RSS Feeds Facebook Twitter Follow Google+

Categories

  • Android Development
  • C++
  • Developer Tips
  • Slash Coding
  • Web Development
    • CSS
    • JavaScript
    • jQuery
    • PHP

Recently Published

  • Moving Ahead from Front End and Android Development
  • How to Export a Project from Android Studio
  • What is jQuery? Let’s Answer this Common Question today!
  • Mobile App Prototyping : Pixate Studio
  • How to Create a Countdown Timer using jQuery

Subscribe to Email Alerts

Eager to learn more from Slash Coding?
Sign up for daily email updates when anything new comes up. Get it straight in your inbox.

Follow Us on Social Media

RSS Feeds Facebook Twitter Follow Google+

Copyright © 2025 · Slash Coding · Powered by the Genesis Framework
Sitemap | Privacy Policy | About | Contact

×
Get Notified of the new Tutorials when they are posted!
Never miss any article update from Slash Coding. Subscribe to email alerts today!