Simple Calculator Android Project Eclipse Download Source Code
here is an android application for calculation wich can do addition, Subtraction,Multiplication and Division
the eclipse project can be downloaded from the below link :
link : https://drive.google.com/file/d/0B2HmQFsBTVGfQzdoeldfam55b2s/edit?usp=sharing
MainActivity.java
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity
{
Button add_button,sub_button,mul_button,div_button,clear_button;
EditText first_num,second_num;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
first_num=(EditText) findViewById(R.id.num1);
second_num=(EditText) findViewById(R.id.num2);
result=(TextView) findViewById(R.id.result);
add_button=(Button) findViewById(R.id.add);
sub_button=(Button) findViewById(R.id.sub);
mul_button=(Button) findViewById(R.id.mul);
div_button=(Button) findViewById(R.id.div);
clear_button=(Button) findViewById(R.id.clear);
add_button.setOnClickListener(new Addition());
sub_button.setOnClickListener(new Subtraction());
mul_button.setOnClickListener(new Multiply());
div_button.setOnClickListener(new Division());
clear_button.setOnClickListener(new Clear());
}
class Addition implements Button.OnClickListener
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String a,b;
Integer finalValue;
a=first_num.getText().toString();
b=second_num.getText().toString();
finalValue=Integer.parseInt(a)+Integer.parseInt(b);
result.setText(finalValue.toString());
}
}
class Subtraction implements Button.OnClickListener
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String a,b;
Integer finalValue;
a=first_num.getText().toString();
b=second_num.getText().toString();
finalValue=Integer.parseInt(a)-Integer.parseInt(b);
result.setText(finalValue.toString());
}
}
class Multiply implements Button.OnClickListener
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String a,b;
Integer finalValue;
a=first_num.getText().toString();
b=second_num.getText().toString();
finalValue=Integer.parseInt(a)*Integer.parseInt(b);
result.setText(finalValue.toString());
}
}
class Division implements Button.OnClickListener
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String a,b;
Integer finalValue;
a=first_num.getText().toString();
b=second_num.getText().toString();
finalValue=Integer.parseInt(a)/Integer.parseInt(b);
result.setText(finalValue.toString());
}
}
class Clear implements Button.OnClickListener
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
first_num.setText("");
second_num.setText("");
result.setText("");
}
}
}
fragment_mail.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Number 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/num1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Number 2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/num2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sub" />
<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mul" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Div" />
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear" />
</LinearLayout>
No comments:
Post a Comment