What errors? On Oct 2, 10:50 pm, Mike karl <[email protected]> wrote: > trying to make a simple Calculator with just the "-" and "=" for a simple > output but my xml and java are erroring like crazy. is my coding wack? heres > the 2 files > any help would be great thanks > > java > > import android.app.Activity; > import android.app.AlertDialog; > import android.os.Bundle; > import android.util.Log; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.EditText; > import android.widget.TextView; > > public class Calculator extends Activity { > public EditText input1; > public EditText input2; > public EditText solution; > public TextView operator; > public Calculator mContext; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > mContext = this; > > setContentView(R.layout.main); > > input1 = (EditText) findViewById(R.id.input1); > input2 = (EditText) findViewById(R.id.input2); > solution = (EditText) findViewById(R.id.solution); > operator = (TextView) findViewById(R.id.operator); > > // We create an OnClick Event in each button. > > Button minusButton = (Button) > findViewById(R.id.minusbutton); > > Button equalButton = (Button) > findViewById(R.id.equalButton); { > > operator.setText("+"); > > } > > }); > > minusButton.setOnClickListener(new OnClickListener() { > > public void onClick(View arg0) { > > operator.setText("-"); > > } > > public void onClick(View arg0) { > > operator.setText("*"); > > equalButton.setOnClickListener(new OnClickListener() { > > private AlertDialog show; > > public void onClick(View arg0) { > > if ((input1.getText().length() == 0) > || > (input1.getText().toString() == " ") > || > (input2.getText().length() == 0) > || > (input2.getText().toString() == " ")) { > > show = new > AlertDialog.Builder(mContext).setTitle("Error") > .setMessage("Some > inputs are empty") > > .setPositiveButton("OK", null).show(); > > } else if (operator.getText().equals("")) { > > show = new > AlertDialog.Builder(mContext).setTitle("Error") > > .setMessage("Operator is null").setPositiveButton( > > "OK", null).show(); > > } else if (operator.getText().equals("+")) { > > double result = new > Double(input1.getText().toString()) > + new > Double(input2.getText().toString()); > > solution.setText(Double.toString(result)); > > } else if (operator.getText().equals("-")) { > > double result = new > Double(input1.getText().toString()) > - new > Double(input2.getText().toString()); > > solution.setText(Double.toString(result)); > > } else if (operator.getText().equals("*")) { > > double result = new > Double(input1.getText().toString()) > * new > Double(input2.getText().toString()); > > solution.setText(Double.toString(result)); > > } else if (operator.getText().equals("/")) { > > double result = new > Double(input1.getText().toString()) > / new > Double(input2.getText().toString()); > > solution.setText(Double.toString(result)); > > } > > } > > }); > > } > > } > > xml > > <?xml version="1.0" encoding="utf-8"?> > <AbsoluteLayout > android:id="@+id/widget0" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > xmlns:android="http://schemas.android.com/apk/res/android" > > <EditText > android:id="@+id/input1" > android:layout_width="175px" > android:layout_height="wrap_content" > android:text="EditText" > android:textSize="18sp" > android:layout_x="66px" > android:layout_y="54px" > > </EditText> > <TextView > android:id="@+id/operator" > android:layout_width="wrap_content" > android:layout_height="wrap_content" > android:text="TextView" > android:layout_x="114px" > android:layout_y="110px" > > </TextView> > <EditText > android:id="@+id/input2" > android:layout_width="175px" > android:layout_height="wrap_content" > android:text="EditText" > android:textSize="18sp" > android:layout_x="64px" > android:layout_y="148px" > > </EditText> > <EditText > android:id="@+id/solution" > android:layout_width="302px" > android:layout_height="wrap_content" > android:text="EditText" > android:textSize="18sp" > android:layout_x="7px" > android:layout_y="380px" > > </EditText> > <Button > android:id="@+id/minusbutton" > android:layout_width="46px" > android:layout_height="wrap_content" > android:text="-" > android:layout_x="124px" > android:layout_y="268px" > > </Button> > <Button > android:id="@+id/equalButton" > android:layout_width="99px" > android:layout_height="wrap_content" > android:text="=" > android:layout_x="95px" > android:layout_y="314px" > > </Button> > </AbsoluteLayout>
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

