Monday, May 30, 2011

Android EMI Calculator





Another basic application with learning objectives as follows

1. Implementing Reset


Intent refresh = new Intent(this, EMICalculator.class);
startActivity(refresh);
this.finish();

Reset basically means resetting all the fields and getting them back to their original state. In this particular code I am implementing reset by closing the current activity and starting it as a fresh activity again.

2. Implementing Menus

Menus can be implemented by adding and xml file in the and inflating it in an activity, we will see this method in some later application. In this application menus are inflated through the code itself.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("About").setIcon(R.drawable.about);
menu.add("Exit").setIcon(R.drawable.exit);
return super.onCreateOptionsMenu(menu);
}

3. Handling Menu click

Menu clicks are handelled in a method called onOptionsItemSelected
if(item.getTitle().equals("About")&&item.getTitle()=="About")
{
Intent i=new Intent(this,About.class);
this.finish();
startActivityForResult(i,0);
}

In this particular piece of code ABOUT menu is clicked, by using equals method its verified that which item is clicked then the a fresh activity is started using an intent. Remember when ever you start a new activity always close the current one. Android apps have to run on phone with limited resources, so an activity should not be left open running behind the scene as it will consume valuable resources of the phone.

4. Implementing Image button

imagebutton id="@+id/home" src="@drawable/home" layout_width="wrap_content" layout_height="wrap_content" clickable="true" onclick="myClickHandler"

One more thing that is used in this code although not from android but java is good to mention. I have used number formatter in order to display the results in a desired format.

NumberFormat formatter = new DecimalFormat("#0.00#");

6 comments:

  1. Thanks for the help...Much appreciated

    ReplyDelete
  2. Bilal it's good approach..keep it up

    ReplyDelete
  3. thanks a ton Asim, Ethical Indian & A biological machine :-)

    ReplyDelete
  4. Is there anything for Nokia 1110 ?
    Sundar, sasta & Maha Tikau

    ReplyDelete
  5. Read your blog its really informative and helpful keep updating with newer post on Emi calculator

    ReplyDelete