package de.deeprojects.speedcalc;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class SpeedCalc extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button calc = (Button) findViewById(R.id.calc);
calc.setOnClickListener(this);
Button delete = (Button) findViewById(R.id.del);
delete.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
item.getItemId();
setContentView(R.layout.about);
return false;
}
public void onClick(View v) {
EditText speed = (EditText) findViewById(R.id.speed);
EditText time = (EditText) findViewById(R.id.time);
EditText way = (EditText) findViewById(R.id.way);
double weg = Double.parseDouble(speed.getText().toString());
double zeit = Double.parseDouble(time.getText().toString());
double kmh = Double.parseDouble(way.getText().toString());
switch (v.getId()) {
case R.id.calc:
// abfrage ob edittext ausgefüllt
if ((weg == 0) && (zeit == 0) && (kmh == 0)) {
new AlertDialog.Builder(this).setMessage(R.string.err)
.setNeutralButton(R.string.error, null).show();
return;
}
//weg berechnen
if ((weg == 0) && (zeit != 0) && (kmh != 0)) {
double aweg = kmh * zeit;
EditText result = (EditText)findViewById(R.id.way);
result.setText(String.format("%.02f", aweg));
}
// //
// // zeit berechnen
// if ((weg.length() != 0) && (zeit.length() == 0)
// && (kmh.length() != 0)) {
// // zeit = weg / kmh
// time.setText("1");
// }
//
// // geschwindigkeit berechnen
// if ((weg.length() != 0) && (zeit.length() != 0)
// && (kmh.length() == 0)) {
// // kmh = weg / zeit
// speed.setText("2");
// }
break;
case R.id.del:
speed.setText("");
way.setText("");
time.setText("");
break;
}
}
}
ich hab so das gefühl das richtig dumme fehler drin sind, hoffe mir kann jemand helfen
gruß dennis