Karşdem ornek olarak atıyorum incele bunları.Kopyala yapıştır çalışır:)
MainActivity
[code]
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
EditText edtText1,edtText2;
Button btnTopla,btnCıkart,btnBol,btnCarp;
String sayi1,sayi2;
int sonuc;
TextView txSonuc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtText1=(EditText)findViewById(R.id.editText1);
edtText2=(EditText)findViewById(R.id.editText2);
txSonuc=(TextView)findViewById(R.id.textView2);
btnTopla=(Button)findViewById(R.id.button1);
btnCıkart=(Button)findViewById(R.id.button2);
btnCarp=(Button)findViewById(R.id.button3);
btnBol=(Button)findViewById(R.id.button4);
btnTopla.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sayi1= String.valueOf(edtText1.getText());
sayi2=String.valueOf(edtText2.getText());
sonuc=Integer.parseInt(sayi1)+Integer.parseInt(sayi2);
txSonuc.setText(String.valueOf(sonuc));
}
});
btnCıkart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sayi1= String.valueOf(edtText1.getText());
sayi2=String.valueOf(edtText2.getText());
sonuc=Integer.parseInt(sayi1)-Integer.parseInt(sayi2);
txSonuc.setText(String.valueOf(sonuc));
}
});
btnCarp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sayi1= String.valueOf(edtText1.getText());
sayi2=String.valueOf(edtText2.getText());
sonuc=Integer.parseInt(sayi1)*Integer.parseInt(sayi2);
txSonuc.setText(String.valueOf(sonuc));
}
});
btnBol.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sayi1= String.valueOf(edtText1.getText());
sayi2=String.valueOf(edtText2.getText());
sonuc=Integer.parseInt(sayi1)/Integer.parseInt(sayi2);
txSonuc.setText(String.valueOf(sonuc));
}
});
}}
[/code]
Xml Layout
[code]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x" />
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sonuc:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
[/code]