unable to lunch Calculator on AVD [message #1454788] |
Tue, 28 October 2014 19:30 |
Eriks Vizums Messages: 4 Registered: October 2014 |
Junior Member |
|
|
Hello, I have a problem with this calculator code,because I think i messed up with library imports.
package eriksdas.kalkulators;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
import android.view.MenuItem;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.util.Log;
public class MainActivity extends Activity {
EditText one,two;
Button plus, minus, multiply,divide;
TextView showres;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one = (EditText)findViewById(R.id.editText1);
two = (EditText)findViewById(R.id.editText2);
plus = (Button)findViewById(R.id.button1);
minus = (Button)findViewById(R.id.button2);
multiply = (Button)findViewById(R.id.button3);
divide = (Button)findViewById(R.id.button4);
showres = (TextView)findViewById(R.id.TextView3);
plus.setOnClickListener((new View.OnClickListener() {
@Override
public void OnClick(View arg0) {
// 1000 Auto-generated method stub
try{
int n1 = Integer.parseInt(one.getText().toString());
int n2 = Integer.parseInt(two.getText().toString());
int sum = n1+n2;
showres.setText(sum);
}
catch(exception e){
}
}
}));
minus.setOnClickListener((new View.OnClickListener() {
@Override
public void OnClick(View arg0) {
// 1000 Auto-generated method stub
try{
int n1 = Integer.parseInt(one.getText().toString());
int n2 = Integer.parseInt(two.getText().toString());
int sum = n1-n2;
showres.setText(sum);
}
catch(exception e){
}
}
}));
multiply.setOnClickListener((new View.OnClickListener() {
@Override
public void OnClick(View arg0) {
// 1000 Auto-generated method stub
try{
int n1 = Integer.parseInt(one.getText().toString());
int n2 = Integer.parseInt(two.getText().toString());
int sum = n1*n2;
showres.setText(sum);
}
catch(exception e){
}
}
}));
divide.setOnClickListener((new View.OnClickListener() {
@Override
public void OnClick(View arg0) {
// 1000 Auto-generated method stub
try{
int n1 = Integer.parseInt(one.getText().toString());
int n2 = Integer.parseInt(two.getText().toString());
int sum = n1/n2;
showres.setText(sum);
}
catch(exception e){
}
}
}));
};
@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;
}
}
[Updated on: Tue, 28 October 2014 19:33] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02903 seconds