Getting the live weight android apps

There is an increase of users using mobile phones today and in the future. In connection with that there are also a demand of mobile apps developer to develop mobile application for android or other platform like Windows and iOS. In this article I would like to share on how to develop or create android application. This basic tutorial on how to develop android application ca help to those beginners who want to become android developers in the future.
 
The android mobile apps that I am going to create is an apps that can be used to estimate the weight of a live pig. The inputs needed are the heart girth of pig and the length of pig in inches. This apps is useful to those who buy and sell pig and the heavy duty weighing scale is not available. The tape measure is used to get the hearth girth and length of pig in inches. To compute the estimated weight of live pig for example, if the pig had a heart girth of 44 inches: 44 x 44 = 1936, multiply the pig's girth measurement by its length.  If our example pig had a length measurement of 39 inches:  1936 x 39 = 75,504, divide your total by 400 to get the estimated total live weight. For example: 75,504 / 400 = 188.76 lbs. Convert it into kilos equivalent using the formula: 188.76 lbs. / 2.2046 = 85kilos is the estimated weight of live pig in kilos.

Here is the java code and xml file for the live pig weight estimate android apps:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="PIG WEIGHT ESTIMATE CALCULATOR"
        android:id="@+id/textView1"
        android:layout_x="23dp"
        android:layout_y="19dp"
        android:autoText="false"
        android:editable="false"
        android:textColor="@android:color/black"
        android:textSize="@dimen/abc_action_bar_content_inset_material"
        android:typeface="sans"> </TextView>

    <TextView android:layout_width="wrap_content"
        android:layout_x="21dp"
        android:layout_height="wrap_content"
        android:text="Heart Girth (inches):"
        android:id="@+id/textView2"
        android:layout_y="95dp"
        android:textColor="@android:color/black"> </TextView>

    <EditText android:text=""
        android:layout_width="99dp"
        android:layout_x="161dp"
        android:id="@+id/hgirth"
        android:layout_height="wrap_content"
        android:layout_y="76dp"
        android:textColor="@android:color/black"> </EditText>

    <TextView android:layout_width="wrap_content"
        android:layout_height="28dp"
        android:text="Lenght (inches):"
        android:id="@+id/textView3"
        android:layout_x="21dp"
        android:layout_y="146dp"
        android:textColor="@android:color/black"> </TextView>

    <EditText android:text=""
        android:layout_width="99dp"
        android:layout_x="161dp"
        android:id="@+id/lenght"
        android:layout_height="wrap_content"
        android:layout_y="128dp"
        android:textColor="@android:color/black"> </EditText>

    <Button android:layout_width="wrap_content"
        android:id="@+id/calculate"
        android:layout_x="54dp"
        android:layout_height="wrap_content"
        android:text="Calculate"
        android:layout_y="310dp"> </Button>

    <Button android:layout_width="102dp"
        android:id="@+id/clear"
        android:layout_x="160dp"
        android:layout_height="wrap_content"
        android:text="Clear"
        android:layout_y="310dp"> </Button>

    <EditText android:text=""
        android:layout_width="285dp"
        android:layout_x="12dp"
        android:id="@+id/tt"
        android:layout_height="wrap_content"
        android:layout_y="188dp"
        android:textColor="@android:color/black"> </EditText>

    <EditText android:text=""
        android:layout_width="288dp"
        android:layout_x="12dp"
        android:id="@+id/tt1"
        android:layout_height="wrap_content"
        android:layout_y="245dp"
        android:textColor="@android:color/black"> </EditText>

    <TextView android:layout_width="wrap_content"
        android:layout_height="28dp"
        android:text="Developed by: JAM"
        android:id="@+id/textView4"
        android:layout_x="99dp"
        android:layout_y="43dp"
        android:textColor="@android:color/darker_gray"> </TextView>
</AbsoluteLayout>

Source Code for MainActivity.java
package com.kid.weightesti;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {
    EditText hgirth;
    EditText lenght;

    TextView tt;
    TextView tt1;
    TextView w;
    TextView l;

    Button calculate;
    Button clear;

    double dblHgirth=0;
    double dblLenght=0;
    double dblSqrGirth=0;
    double dblSqrXlenght;
    double dblLiveWeight;
    double dblPoundsToKilo;
    double carcass;
    double butcher;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initControls();

    }
    private void initControls()
    {
        hgirth=(EditText)findViewById(R.id.hgirth);
        lenght=(EditText)findViewById(R.id.lenght);
        tt=(TextView)findViewById(R.id.tt);
        tt1=(TextView)findViewById(R.id.tt1);

        calculate=(Button)findViewById(R.id.calculate);
        calculate.setOnClickListener(new Button.OnClickListener() {
            public void onClick
                    (View v) {
                calculate();
            }
        });

        clear=(Button)findViewById(R.id.clear);
        clear.setOnClickListener(new Button.OnClickListener() {
            public void onClick
                    (View c) {
                clear();
            }
        });
    }
    private void calculate()
    {
        if((hgirth.getText().toString().equals("")) || (lenght.getText().toString().equals("")) ) {
           Toast.makeText(getApplicationContext(),"Please enter numeric input", Toast.LENGTH_LONG).show();
        }else {
            dblHgirth = Double.parseDouble(hgirth.getText().toString());
            dblLenght = Double.parseDouble(lenght.getText().toString());
            dblSqrGirth = dblHgirth * dblHgirth;
            dblSqrXlenght = dblSqrGirth * dblLenght;
            dblLiveWeight = dblSqrXlenght/400;
            dblPoundsToKilo = dblLiveWeight * 0.455;
            carcass = dblLiveWeight * 0.72;
            butcher = carcass * 0.455;

            tt.setText( String.format( "Live: %.2f", dblPoundsToKilo ) + " " + "kilos" );
            tt1.setText( String.format("Butcher: %.2f", butcher) + " " + "kilos" );
           //tt.setText("Live: " + Double.toString(dblPoundsToKilo) + " " + "Kilos");
            //tt1.setText("Butcher: " + Double.toString(butcher) + " " + "Kilos");
        }
    }

    private void clear()
    {
        tt.setText("");
        tt1.setText("");
        hgirth.setText("");
        lenght.setText("");
        EditText mEdit;
        mEdit = (EditText)findViewById(R.id.hgirth);
        mEdit.requestFocus();
    }
}