Calculator
package cal.tr;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class CalculatorActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
EditText et1,et2,et3;
Button bt;
CheckBox sub,mul,add;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt=(Button) findViewById(R.id.bt);
bt.setOnClickListener(this);
add=(CheckBox)findViewById(R.id.ad);
et1=(EditText) findViewById(R.id.et1);
et2=(EditText) findViewById(R.id.et2);
et3=(EditText) findViewById(R.id.et3);
}
@Override
public void onClick(View v) {
if(add.isChecked())
{
double a=Double.parseDouble(et1.getText().toString()); //string to double
double b=Double.parseDouble(et2.getText().toString()); //string to double
double c=a+b;
// or
// String d=""+c;
//et3.setText(d);
et3.setText(Double.toString(c)); //double to string
}
}
}
</div>
..........................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Multiplicayion"
android:id="@+id/mul"
android:layout_x="60dp"
android:layout_y="146dp"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Addition"
android:id="@+id/ad"
android:layout_x="59dp"
android:layout_y="199dp">
</CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Subtraction"
android:id="@+id/sub"
android:layout_x="60dp"
android:layout_y="266dp">
</CheckBox>
<EditText android:layout_height="wrap_content"
android:id="@+id/et1"
android:layout_y="62dp"
android:layout_width="38dp"
android:layout_x="35dp">
</EditText>
<Button android:layout_width="49dp"
android:layout_height="wrap_content"
android:text="=" android:id="@+id/bt"
android:layout_x="141dp"
android:layout_y="64dp">
</Button>
<EditText android:layout_width="64dp"
android:layout_height="wrap_content"
android:id="@+id/et3"
android:layout_x="200dp"
android:layout_y="66dp">
</EditText>
<EditText android:layout_width="37dp"
android:layout_height="wrap_content"
android:id="@+id/et2" android:layout_x="84dp"
android:layout_y="65dp"></EditText>
</AbsoluteLayout>
-------------------------------------------------------------------------