Results 1 to 11 of 11
  1. #1
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed

    My first Android Application - Basic(s)

    Creating Your First Android Application.

    {Note: This article assumes you know at least the basics of Java Development and have already read the 2 prior articles:
    Part 1: https://www.mpgh.net/forum/511-androi...endations.html
    Part 2:
    https://www.mpgh.net/forum/511-androi...r-options.html
    (Link Backs to Personal Site Article)
    Part 1:
    Android SDK Installation & Recommendation(s) | Innovators World Wide
    Part 2:
    Best Option for Emulating Android OS & Other Options | Innovators World Wide
    }



    At the end of Article #2 {Best option for....) I discussed how creating a "Hello World" application wouldn't be the most effective way to learn Android Development basics, the reason(s) for this is:

    1. Android SDK automatically generated a "Hello World" application, so what would that lead you to do {which is the common first application when learning a new language, yet for some reason it seems to be {still} the most commonly used tutorial in android. So I wanted to take it a step forward and create a "complete" application that has function.
    2. I have never believed you could learn much from getting an application to display the phrase "Hello World" I think it lacks in actual demonstration.

    What we will be doing.

    Creating a RSS Feed (Parser) for MPGH using Native UI and Java Objects

    What is an RSS Feed?

    RSS (originally RDF Site Summary, often dubbed Really Simple Syndication) is a family of web feed formats used to publish frequently updated works—such as blog entries, news headlines, audio, and video—in a standardized format.[2] An RSS document (which is called a "feed", "web feed",[3] or "channel") includes full or summarized text, plus metadata such as publishing dates and authorship. (wikipedia)
    .

    Before we can start diving into the RSS Parser, you should learn some basics about Java and more specifically Android (SDK). Here are a few "Terms" I will be using a lot in my articles.

    Articles

    Everything you seen on a Android Screen during application use (mostly) is a activity. You can create an activity by implementing the activity class, like the example below

    You can create an activity just by implementing the Activity base class as shown below.

    'Remember the class name will be the name of the class you created for your application (more on that later)

    Code:
    public class ClassName extends Activity{
    //extend the base class Activity and implement the onCreate method
    @override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    }
    }
    


    View
    View class is the base class for Widgets.

    What is a Widget?


    Well, You may be thinking of the "widgets" that sit on your home screen, in this case I am referring to buttons, textboxs , etc

    View Group

    What is a View Group?

    A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. This class also defines the ViewGroup.LayoutParams class which serves as the base class for layouts parameters.


    List of Android Widgets:

    (Views)
    • EditBox
    • Spinner
    • Button
    • CheckBox
    • Radio Button
    • WebView
    • TextView
    • List View
    Layouts also constitute as part of the "Widget ToolKit"
    • Linear (Layout)
    • Relative (Layout)
    • Table (Layout)
    • Frame (Layout)
    • Absolute (Layout)


    Now that we are done with the basic definitions and terms you may here during these articles, let's move on to some basic lessons.

    Lesson (ONE)

    In Eclipse while utilizing the Android SDK you can build application interfaces in two basic ways, One way is by using XML .

    So , Let's start there.

    {Note:You should have eclipse open, and your project from the last 2 articles open, if you don't go ahead and open eclipse, all projects should automatically load from the workspace, you shouldn't need to open or import any files. }

    First, In your Package Explorer {On the left side of the IDE} expand the project.

    You should now see some folders and files.

    It should look something like this.



    now, expand the resource (res) folder, then the layout folder.


    Double click the main.xml file located in the layout folder.

    You should see a screen that looks like the image below in the codeview (edit) part of eclipse.



    What this is (is) a graphical designer for main.xml, however as a developer you should stay away from the WYSIWYG designers and view the code, this will prepare you and make you better equipped to deal with issues as they occur, it is always better to know what is going on then not understand the code structure because you used a Graphical Editor. (I will however talk to about Graphical Editors and XML Generators in another article & explain when you may want to use such an editor)

    In order to view the XML in eclipse, you need to change from the Graphical editor to the code view , you can find this on the bottom of the current view, use the image below as a guide (click the tab labeled main.xml)



    you should now have a view that looks like this.



    Here is the code you should now be able to edit.

    Code:
    
    
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
    
    </LinearLayout>
    Needles to say , modifying the source above will also modify the graphical layout editor, and what appears in the Main Activity.

    So to complete this Article before moving forward, let's add some basic objects.

    (Note: if you forget or need help loading a specific object, feel free to switch back to the graphical editor and add an element that way, but immediately return to the code screen, learn what it is the Graphical editor did for you, and keep it in mind when moving forward.)

    First thing you should notice in your XML is you have a piece of code in there already which populates a string.

    Code:
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    You can edit this if you like, however I suggest (if you are not familiar with android or XML, you wait until the next article, The XML code above is creating a String (using the textview object) It sets it's width to fill the activity from left to right and it's height to match the height of the content.

    The next part of the code determines the text, in this case what you are seeing is text populated from another XML, this XML is the string.xml located /res/values/strings.xml. Now (again) you don't need to modify this for this article, however I would like to explain it briefly.

    Code:
    android:text="@string/hello" />
    (more literal translation) , within the Android SDK, the text of this textview will be = the hello string as written within the strings.xml file.

    Here is a current copy of strings.xml (as generated by android sdk during project creation)

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
    
        <string name="hello">Hello World, MPGH_Article_2Activity!</string>
        <string name="app_name">MPGH_Article_2</string>
    
    
    </resources>
    Now if you wanted to edit the "Hello World" text you would do it on the first line.

    for example

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
    
        <string name="hello">This is my first application</string>
        <string name="app_name">MPGH_Article_2</string>
    
    
    </resources>


    If you did this, when you viewed the main.xml in the graphical layout you would see the new text in it's place.
    You could also add a new string as well.

    Code:
    
    
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
    
        <string name="hello">Hello World, MPGH_Article_2Activity!</string>
        <string name="main_text">Welcome to my application</string>
        <string name="app_name">MPGH_Article_2</string>
    
    
    </resources>


    now, in main.xml you can change the textview string information like the code below.

    Code:
    
    
    Code:
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/main_text" />

    The purpose of me showing you all this was to give you an idea of some back and forth movements you may be making to edit your main.xml file successfully, you could have just hardcoded the text in the main.xml, but I wanted you to understand this method for a reason (in a future article, when we discuss color backgrounds and etc.)

    okay, so lets add two new objects and finish this article up for now.

    We will be adding a TextBox and a Button, the XML for that is as such.

    Button: (XML is order based, so in this case, you will want to add the texbox first, then the button, otherwise in the layout it will be button, then textbox)

    Code:
    
    
    Code:
     <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName" >
        </EditText>
    Now because this is a textbox, we want to have it get focus when the page loads, this way the application user does not have to manually click it to start typing.

    the way we do that is by adding

    Code:
            <requestFocus />
    within the EditText element.

    Code:
    <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName" >
    <requestFocus />
        </EditText>
    {Note: @+id/editText1 is code that automatically creates a new id called editText1 }

    now to add our button.

    Code:
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    Your final main.xml should look like this now.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
    
        <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName" >
    
    
            <requestFocus />
    
    
        </EditText>
    
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
    
    </LinearLayout>
    Okay, It's time I end this article, Next Article we will discuss layouts, and start the RSS Feed.








    .
    Last edited by NextGen1; 02-26-2012 at 05:53 PM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  2. The Following 3 Users Say Thank You to NextGen1 For This Useful Post:

    Delko DJ (11-29-2012),THEBOYZRULE (08-04-2012),unspeakable (09-11-2012)

  3. #2
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Another long article complete.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  4. #3
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Nice. Keep 'em coming :P

  5. The Following User Says Thank You to Hassan For This Useful Post:

    NextGen1 (02-27-2012)

  6. #4
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Quote Originally Posted by Hassan View Post
    Nice. Keep 'em coming :P
    10/4, will do.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  7. #5
    unspeakable's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Location
    WorldWide
    Posts
    73
    Reputation
    21
    Thanks
    7
    My Mood
    Dead
    hi there nextgen1 i hope you keep the android app dev up,

    i havent been thru your tu completely just yet but do i need to learn XML to make full utilisation of the the android SDK?
    i know java and cpp by the way.

    recommendation for your tut: add a link yo the android API(reference) for people to learn about other functions.
    "out out , brief candle" life is a matter of seconds.

  8. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by unspeakable View Post
    hi there nextgen1 i hope you keep the android app dev up,

    i havent been thru your tu completely just yet but do i need to learn XML to make full utilisation of the the android SDK?
    i know java and cpp by the way.

    recommendation for your tut: add a link yo the android API(reference) for people to learn about other functions.
    You need to learn XAML for layout purposes.

    Extensible Application Markup Language - Wikipedia, the free encyclopedia

  9. #7
    unspeakable's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Location
    WorldWide
    Posts
    73
    Reputation
    21
    Thanks
    7
    My Mood
    Dead
    WHAT does @override mean? i know what overriding means but i dont understand why you have to write it like that.

    and also in order to learn XAML you need to have prior exp in HTML.this is going to take some time

    ty for the linky anway

    @NextGen1: when is the next tut series coming out?
    Last edited by unspeakable; 09-19-2012 at 12:34 PM.
    "out out , brief candle" life is a matter of seconds.

  10. The Following User Says Thank You to unspeakable For This Useful Post:

    NextGen1 (11-18-2012)

  11. #8
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by unspeakable View Post
    WHAT does @override mean? i know what overriding means but i dont understand why you have to write it like that.

    and also in order to learn XAML you need to have prior exp in HTML.this is going to take some time

    ty for the linky anway

    @NextGen1: when is the next tut series coming out?
    Last Activity: 07-01-2012

    There are tutorials like this on the android w/e page, just look into it. (loads of it)
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  12. #9
    Hardstyle is more than music, it's a way of life.
    MPGH Member
    remcov's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    ✯✯✯✯✯ - Luxery Hotel!
    Posts
    842
    Reputation
    74
    Thanks
    611
    My Mood
    Cool
    I got a great idea for an app, i private message you. i think this can be really get popular.

    Windows 8 Users Group Click Here:



  13. #10
    unspeakable's Avatar
    Join Date
    Mar 2012
    Gender
    male
    Location
    WorldWide
    Posts
    73
    Reputation
    21
    Thanks
    7
    My Mood
    Dead
    Quote Originally Posted by Brinuz View Post


    Last Activity: 07-01-2012

    There are tutorials like this on the android w/e page, just look into it. (loads of it)
    i found some good ones that show you how to do a particular thing but are there any tutorials that show you how to make a good app from start to finish? apart from the notepad one/
    "out out , brief candle" life is a matter of seconds.

  14. #11
    akosinivenz's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Posts
    10
    Reputation
    10
    Thanks
    0
    My Mood
    Breezy
    thnx for this

Similar Threads

  1. [Video] Cool application for Android phones!
    By jijsucktnoob in forum General
    Replies: 35
    Last Post: 02-08-2012, 03:08 AM
  2. MPGH IPhone/Android Application
    By Dave84311 in forum General
    Replies: 132
    Last Post: 12-04-2010, 08:53 PM
  3. [TuT] You First C++ Console Application
    By sam22 in forum Programming Tutorials
    Replies: 6
    Last Post: 11-30-2010, 07:56 PM
  4. Supb's first C++ APPLICATION
    By SupB in forum C++/C Programming
    Replies: 2
    Last Post: 08-02-2009, 10:11 AM
  5. KSSN Generator *My first C++ Application*
    By Hyperion in forum WarRock Korea Hacks
    Replies: 7
    Last Post: 04-10-2009, 06:45 PM