Portfolio

Wednesday, December 23, 2015

How to build a Simple Converter App in Android




Introduction

Basically, I just got started in creating Android apps just to build some other skills under my belt.  I thought it would be fun and interesting to build something small and learn something totally new.  I'm used to creating windows applications and software in C#, so learning Java was a huge difference to me in terms of the language, methods, and variables.  If you are curious about learning mobile apps I highly recommend learning Android only because the market is huge and it's the number one thing that will make you marketable when looking for a career.  

How to Get Started

You can begin by learning on your own with tutorials online.  I would start with free resources online and looking through people's code on various websites and just trying it out.  I also suggest reading through blog posts and manuals to get familiar with the structure.  Finding the best one possible can be a drag, but trust me there are reliable data out there.  Moreover,  I highly suggest looking at Android's website that has the majority of the information on what you're looking for anyway.  You will need to download the Android studio and the latest Java program.  Make sure you have the most updated version.  

Lets look at the Source Code

Make sure you have the necessary imported libraries from Android located at the very top of the code.  Majority of the code will be in the on create section that does the activities.  

Instructions:

  • Start with a new project and name your application ConverterApp (sorry it's so small)
  • Second, choose an API that will serve all mobile devices.  I chose API 8 froyo because it serves majority of Android devices, such 100%
  • Next, choose blank activity for your device
  • On the next screen choose Main Activity for your activity name
  • On the left side under your project there's files double click the project and open up your source folder, main and java folder, there you will work out of the main activity.java folder, the mainActivity.xml folder and the layout folder located under AndroidManifest.xml folder
  • All the source code will be in the main activity.java folder
  • After you open up your layout make sure you choose API 18 or higher because I had some problems working with API 23.
  • If you get lost there's a really excellent tutorial from the Newboston on Youtube I highly recommend.  He's funny and enjoyable to watch.  He explains Android in the most simplest form possible and that's how I learned.
  • Lastly, copy down this source code and insert the code in the java file.
  • Source Code: (Converting centimeters to inches)

Centimeters to inches Converter App(Android):  Written in Java 
December 6, 2015
package com.logizticsinc.converterapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewDebug;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final EditText editCentimeters = (EditText) findViewById(R.id.editCentimeters);
        final EditText editInches = (EditText)findViewById(R.id.editInches);

        Button buttonConvert = (Button)findViewById(R.id.buttonConvert);
        buttonConvert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                double centimeters = Double.valueOf(editCentimeters.getText().toString());
                double inches = centimeters * 0.39370079;
                editInches.setText(String.valueOf(inches));
            }
        });

    }





    }


No comments:

Post a Comment