Create a cool app like Calc



Hii guys  ...
Now lets make an Calc App

##
First of all make sure u have all tools and started the android emulator
##


(1)  In eclipse goto file->new -> android project and give the Project Name as : "MyCalc".
Click next -> select ur build target that is the version that u want the app for (I chosed android 4.0.3)

(2)  Give package name as "com.dia.mycalc"  (here "dia" means "dream in android" )

(3)  Now open MyCalcActivity.java file.  This is the base class and all other classes will extend this one.
remove "onCreate()" method from this one. If u want to have any constant values u should put them over here.

(4)  Create a new class inside the com.dia.mycalc   called "MyCalcSpashActivity.java". This is the class that will handle all the operations related to splash screen. Make this class extend "MyCalcActivity" class. Also make another class called "MyCalcMainActivity.java" and extend MyCalcActivity class.

(5)  Now goto res -> layout  -> right click on it  ->  new-> Android XML File
Select linear layout and give a name as "splashscreen". Delete the main.xml there as its not neaded at all now.

(6) open splashscreen.xml and select Graphical layout it not selected.

(7) Make  the splash screen as you want. Here I am making it as simple Image. Later we will deal with complex animations.

  goto images and media -> ImageView and drag it to screen.


(8) Goto resources again and add image to drawable-hdpi (right click -> import -> file system-> browse and select your image)

here is my image i used
Now all you have to do is right click th imageview -> edit src -> image.png

(9)  Similarly create another layout mainscreen.xml

(10)  Put 2  linear layout(horizontal) one below other.
 
 

From Form tab drag and put an textview on each horizontal layouts.

 

Set the textview text property as : Num1 for upper box and Num2 for lower one.

 Beside each Text view put an edittext box .


Change the ID of both edit text box as box1 and box2

(12)  In the end just put a button and change its id to sumbtn.

(13)  Now your GUI is done. 

Here is the code for "MyCalcSpashActivity.java" 

package com.dia.mycalc;

import android.content.Intent;
import android.os.Bundle;

public class MyCalcSplashActivity extends MyCalcActivity{
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivity(new Intent(MyCalcSplashActivity.this, MyCalcMainActivity.class));
}
}

Here is the code for "MyCalcMainActivity.java" 



package com.dia.mycalc;

import android.os.Bundle;

public class MyCalcMainActivity extends MyCalcActivity{
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainscreen);
       
}
}

No comments:

Post a Comment