Witam,
mam napisać kalkulator, robiłem go w programie eclipse według tego tutoriala
do robienia switcha wszystko chodziło jak powinno jednak potem przestało, program nie wykonuje działań, tak jakby nie czytał switcha. Proszę o pomoc.
package com.example.kalk2;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView Disp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Disp=(TextView)findViewById(R.id.textView1);
Disp.setText("0");
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
static boolean isempty=true;
public void num_Clicked(View sender)
{
Button bt=(Button)sender;
if(Disp.getText().length()>9)return;
if(isempty)
{
if(bt.getText().toString().equals("0"))return;
Disp.setText(bt.getText());
isempty=false;
}
else{
Disp.append(bt.getText());
}
}
static int ac=0;
static short op=0;
public void op_Clicked(View sender)
{
Button bt=(Button)sender;
switch (op)
{
case 0:
ac+=Integer.parseInt(Disp.getText().toString());
break;
case 1:
ac-=Integer.parseInt(Disp.getText().toString());
break;
case 2:
ac+=Integer.parseInt(Disp.getText().toString());
break;
case 3:
ac+=Integer.parseInt(Disp.getText().toString());
break;
}
Disp.setText(Integer.toString(ac));
if(bt.getText().toString().equals("+")) op=0;
if(bt.getText().toString().equals("-")) op=1;
if(bt.getText().toString().equals("*")) op=2;
if(bt.getText().toString().equals("/")) op=3;
isempty=true;
}
}