Saturday, 23 May 2015

Simple EMI Loan calculator android example

44 comments
In this example we learn, how to write simple EMI Loan Calculator. in this example user can calculate loan amount as per monthly installment (e.g pay monthly 1000rs.) or monthly time period (e.g.10 month)with interest rate.

CREATE NEW PROJECT


Step 1:Write code into activity_main.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

        <LinearLayout

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText

                android:id="@+id/etLoanAmount"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="   LoanAmount"
                android:inputType="numberDecimal"
                android:textColor="#fff"
                android:textSize="25sp" />

            <EditText

                android:id="@+id/etInterest"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="   Annuan Interest Rate"
                android:inputType="numberDecimal"
                android:textColor="#fff"
                android:textSize="25sp" />

            <Spinner

                android:id="@+id/sp1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:spinnerMode="dialog" />

            <EditText

                android:id="@+id/e1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="Enter value"
                android:inputType="numberDecimal"
                android:textColor="#fff"
                android:textSize="25sp" />

            <Button

                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Calculate"
                android:textColor="#fff"
                android:textSize="20dp" />

            <TextView

                android:id="@+id/etAns"
                android:layout_width="match_parent"
                android:layout_height="38dp"
                android:ems="10"
                android:hint="  Answer"
                android:textColor="#fff"
                android:textSize="25sp" >

                <requestFocus />

            </TextView>
       </LinearLayout>
</LinearLayout>

Step 2: Write code into spineritem.xml 


its custom spiner, you can create your own style.e.g change background color or font color etc.



<TextView xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:textStyle="italic"
    android:fadingEdgeLength="20dp"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="15dp"
    android:textColor="#0594A8"
    android:textSize="25sp" >


</TextView>

Step 3: Write code into MainActivity.java


package com.loancalculator.calLoan;


import java.util.ArrayList;

import java.util.List;

import android.os.Bundle;

import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {


Spinner sp1;

Button button1, bthlp;
Float f1, f2, f3, f4, f5, f6;
EditText etLoanAmount, etInterest, etAns, e1;
TextView tvans;

@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp1 = (Spinner) findViewById(R.id.sp1);
button1 = (Button) findViewById(R.id.button1);
etLoanAmount = (EditText) findViewById(R.id.etLoanAmount);
etInterest = (EditText) findViewById(R.id.etInterest);
e1 = (EditText) findViewById(R.id.e1);

tvans = (TextView) findViewById(R.id.etAns);


List<String> list = new ArrayList<String>();

list.add("Select a type");
list.add("Monthly time Period");
list.add("Installment price");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
R.layout.spineritem, list);
sp1.setAdapter(dataAdapter);

sp1.setOnItemSelectedListener(new OnItemSelectedListener() {


@Override

public void onItemSelected(AdapterView<?> parent, View arg1,
int pos, long id) {
// TODO Auto-generated method stub

String s = parent.getItemAtPosition(pos).toString();


if (s.equals("Monthly time Period"))

{
button1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {
// TODO Auto-generated method stub


String a = etLoanAmount.getText().toString();
String m = etInterest.getText().toString();
String d = e1.getText().toString();

if(a.length()<=0 || m.length()<=0 ||d.length()<=0)
{
Toast.makeText(getApplicationContext(), "Empty Text Field Enter Data ", Toast.LENGTH_LONG).show();
}
else
{
f1 = Float.parseFloat(etLoanAmount.getText()
.toString());

try {


f2 = Float.parseFloat(etInterest.getText()

.toString());
} catch (NumberFormatException e) {
// TODO: handle exception
e.printStackTrace();
}

f5 = Float.parseFloat(e1.getText().toString());


f3 = (f1 * f2 / 100);

f4 = f3 + f1;
f6 = f4 / f5;
String s2 = String.valueOf(f6);
tvans.setText(s2 + " Rs Installment");


}

}
});
}
if (s.equals("Installment price")) {
button1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {
// TODO Auto-generated method stub


String a = etLoanAmount.getText().toString();
String m = etInterest.getText().toString();
String d = e1.getText().toString();

if(a.length()<=0 || m.length()<=0 ||d.length()<=0)

{
Toast.makeText(getApplicationContext(), "Empty Text Field Enter Data ", Toast.LENGTH_LONG).show();
}

else{
f1 = Float.parseFloat(etLoanAmount.getText()
.toString());
try {
f2 = Float.valueOf((etInterest.getText()
.toString()));

} catch (NumberFormatException e) {

// TODO: handle exception
e.printStackTrace();
}

f5 = Float.parseFloat(e1.getText().toString());


f3 = (f1 * f2 / 100);

f4 = f3 + f1;
int f6 = (int) (f4 / f5);
int f7 = (int) (f4 % f5);
String s2 = String.valueOf(f6);
tvans.setText(s2 + "    Month      " + f7
+ " Rs "+ "Remaing Money");

}

}
});
}

@Override

public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}

});
}

@Override

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


}

NOTE: no need any special permission into AndroidManifest.xml


Step 4: Run Your EMI loan converter.






Download @ Play store:


44 comments :

  1. Thanks for posting this code needed to calculate the loan. Loan Calculator

    ReplyDelete
    Replies
    1. Thank you sir, your good wishes give me more confidence to write new and improved programs.

      Delete
  2. Hey Thanks for sharing this informative blog, it seems very helpful. i was looking for same kind of content about Emi for home loan

    ReplyDelete
    Replies
    1. hello sir,it's my pleasure sir, you like my code and its helpful for you. i will try my best to updating new and improved contents,programming about Emi.
      thank you sir.

      Delete
  3. it's my pleasure sir that you really think this blog is helpful and informative. i will try my best to updating best examples of android and about home loan.
    thank you sir.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. Hey thanks for this amazing post. Would love to read more of such blogs. You can also have a look at EMI Calculator for more information.

    ReplyDelete
  6. Loan calculator

    to get more - http://tunaikoop.com/

    Get the lowest interest rates & immediate approvals on your personal loans, Government loans, Unsecured loans and easy online loan calculations via our mobile app.

    ReplyDelete

  7. Do you need Personal Loan?
    Business Cash Loan?
    Unsecured Loan
    Fast and Simple Loan?
    Quick Application Process?
    Approvals within 24-72 Hours?
    No Hidden Fees Loan?
    Funding in less than 1 Week?
    Get unsecured working capital?
    Contact Us At :oceancashcapital@gmail.com
    Phone number :+16474864724 (Whatsapp Only)

    LOAN SERVICES AVAILABLE INCLUDE:
    ================================
    *Commercial Loans.
    *Personal Loans.
    *Business Loans.
    *Investments Loans.
    *Development Loans.
    *Acquisition Loans .
    *Construction loans.
    *Credit Card Clearance Loan
    *Debt Consolidation Loan
    *Business Loans And many More:

    LOAN APPLICATION FORM:
    =================
    Full Name:................
    Loan Amount Needed:.
    Purpose of loan:.......
    Loan Duration:..
    Gender:.............
    Marital status:....
    Location:..........
    Home Address:..
    City:............
    Country:......
    Phone:..........
    Mobile / Cell:....
    Occupation:......
    Monthly Income:....

    Contact Us At oceancashcapital@gmail.com
    Phone number :+16474864724 (Whatsapp Only)

    ReplyDelete
  8. Thank you for your blog! It is really worth sharing and I'm glad that it helped me find RapidRupee app which provides personal loan calculator & it is great.

    ReplyDelete
  9. Financial Restoration Through Le_Meridian Funding Service Investment. Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.com
    I'mLeonardo Hugo a agronist who was able to revive his dying Livestock Feed Manufacturing through the help of a GodSent lender known as Benjamin Briel Lee the Loan Officer of Le_Meridian Funding Service. I want you to know that Le_Meridian Funding Service is the right place for you to resolve all your financial problem because am a living testimony and I can't just keep this to myself when others are looking for a way to be financially lifted. I want you all to contact this God sent lender using the details as stated in other to be a partaker of this great opportunity and also they work with good/reputable bank that wire money transfer without delay into my account.

    ReplyDelete
  10. Just can’t help to think, how a person can write such amazing stuff.
    mortgage calculator

    ReplyDelete
  11. Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us. online antiderivative calculator

    ReplyDelete

  12. This is really good information I have visited this blog to read something fresh and I really admire you efforts in doing so.


    Download Now Tradeinsta Best Mobile Trading App

    ReplyDelete
  13. A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. ขายฝากบ้าน

    ReplyDelete
  14. Its an extraordinary delight perusing your post.Its loaded with data I am searching for and I want to post a remark that "The substance of your post is marvelous" Great work.
    Love what you're doing here folks, keep it up!.. best online installment loans

    ReplyDelete
  15. Yes i am completely concurred with this article and i simply need say this article is extremely pleasant and exceptionally instructive article.I will make a point to be perusing your blog more. You made a decent point however I can't resist the urge to ponder, shouldn't something be said about the other side? !!!!!!THANKS!!!!!! Canadian Singles looking for Marriage

    ReplyDelete
  16. Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! text auto reply android

    ReplyDelete
  17. Attractive, post. I just stumbled upon your weblog and wanted to say that I have liked browsing your blog posts. After all, I will surely subscribe to your feed, and I hope you will write again soon! android text auto reply

    ReplyDelete
  18. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. out of office text

    ReplyDelete
  19. Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. Auto Reply while Driving

    ReplyDelete
  20. Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. Drive Safely

    ReplyDelete
  21. This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates. Auto Reply while Driving

    ReplyDelete
  22. I exactly got what you mean, thanks for posting. And, I am too much happy to find this website on the world of Google. Drive Safely

    ReplyDelete
  23. Auto loan calculator Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me.

    ReplyDelete
  24. Different types of calculations including those related to property taxes, insurance, income tax benefits,matrix calculator and house loans can be easily carried out by these calculators.

    ReplyDelete
  25. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. 借錢

    ReplyDelete
  26. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. 借錢

    ReplyDelete
  27. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. 借錢

    ReplyDelete
  28. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. 借錢

    ReplyDelete
  29. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. 借款

    ReplyDelete
  30. The iPhone is a smartphone developed by Apple. The first iPhone was released in June, 2007 and an updated version has been released roughly every year since then. Yet with all the features there sometimes arises the need for iPhone repairs. spotify++ ipa

    ReplyDelete
  31. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. snabb kredit

    ReplyDelete
  32. I found Hubwit as a transparent s ite, a social hub which is a conglomerate of Buyers and Sellers who are ready to offer online digital consultancy at decent cost. Loan broker

    ReplyDelete
  33. Qualifying for a loan on an investment property can be difficult for several investors, considering the rules and regulations required to meet, financial concerns for a down payment or credit ratings to qualify for a particular loan, so as you continue on in this article find out the difference and breakdown of conventional and non-conventional loans to give you a better sense of what to expect as you apply for a home loan. Conventional Loans - Conventional loans are any mortgage loan that is not guaranteed or insured by the federal government however they are considered... singapore business loan

    ReplyDelete
  34. Thanks for giving so much of Information. Thinking about buying a car online choose Carmoola

    Buying a Car Online
    Can I Get Car Finance?

    ReplyDelete
  35. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. mortgage avant

    ReplyDelete
  36. Very useful Post. I found so many interesting stuff in your Blog especially its discussion. Munafawala is Best Loan Company in Jaipur Offers Different Types of Bank Loans in Jaipur, Loan Against Property, Personal Loan, Home & Small Business Loans.

    Loan against Property Agency
    Personal Loan Agents in Jaipur

    ReplyDelete
  37. This blog is really helpful regarding all educational knowledge I earned. It covered a great area of subject which can assist a lot of needy people. Everything mentioned here is clear and very useful.
    Car Finance Questions

    ReplyDelete
  38. How the Loan Calculator is measure is shown in the blog. For the calculation this app helps to calculate loan.

    ReplyDelete
  39. I found the Personal Loan Repayment Calculator incredibly helpful! It made planning my finances a breeze, allowing me to budget effectively and save on interest. A must-have tool for anyone considering a loan.

    ReplyDelete

Follow me Share