Having a string of numbers display on click.

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 5174 Views - Last Post: 25 September 2012 - 02:06 PM

#16 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 24 September 2012 - 08:25 AM

View PostEndLessMind, on 24 September 2012 - 04:33 AM, said:

Oh, right. The the AutoCompleteTextView i'm thinking of.
The just use "setText("");"


That works fine but the program still crashes when I press equal. Do I need another function like this maybe:

public void answer(int value){ 
			value.setText(Int.toString(val));
		}
			});
		}


to handle the output?
Was This Post Helpful? 0
  • +
  • -

#17 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 24 September 2012 - 12:40 PM

No, that should not be needed.
But i also seems like you have a space in the string from the EditText.
Errors:
unable to parse ' 1' as integer
unable to parse ' 8' as integer
unable to parse ' 777' as integer

Change: numbers.add(Integer.parseInt(calculations.getText().toString()));
to :
numbers.add(Integer.parseInt(calculations.getText().toString().replace(" ", "")));
Was This Post Helpful? 0
  • +
  • -

#18 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 24 September 2012 - 04:22 PM

Shouldn't
.replace(" ", "")));
be
.replace(" ", " ")));
? ".Replace" is supposed to clear the current number in the textbox right? Also, the program still crashes for some reason when I press equal. I believe the function that controls the equal button isn't getting the values which makes me think my loop isn't correct. I'll look it over anyway.

This post has been edited by izic: 24 September 2012 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

#19 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 24 September 2012 - 04:36 PM

No, when we get the String from the EditText, we want to remove any spaces.
replace(oldchar, newchar) takes the string, and replace every "oldchar" then the newchar.
The oldchar i this case is a space (" "), and we want to remove it so we replace it with nothing ("")
If it still crashes with that code, then please post a new outcast from you logcat.

You can also try
numbers.add(Integer.parseInt(calculations.getText().toString().substring(1,calculations.getText().toString().length() -1)));

This post has been edited by EndLessMind: 24 September 2012 - 04:37 PM

Was This Post Helpful? 0
  • +
  • -

#20 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 24 September 2012 - 05:06 PM

Logcat

09-24 22:36:44.424: ERROR/BatteryService(59): usbOnlinePath not found
09-24 22:36:44.424: ERROR/BatteryService(59): batteryVoltagePath not found
09-24 22:36:44.424: ERROR/BatteryService(59): batteryTemperaturePath not found
09-24 22:36:44.504: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
09-24 22:37:01.234: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
09-24 22:37:01.234: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
09-24 22:37:01.574: ERROR/System(59): Failure starting core service
09-24 22:37:01.574: ERROR/System(59): java.lang.SecurityException
09-24 22:37:01.574: ERROR/System(59):     at android.os.BinderProxy.transact(Native Method)
09-24 22:37:01.574: ERROR/System(59):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
09-24 22:37:01.574: ERROR/System(59):     at android.os.ServiceManager.addService(ServiceManager.java:72)
09-24 22:37:01.574: ERROR/System(59):     at com.android.server.ServerThread.run(SystemServer.java:184)
09-24 22:37:02.664: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
09-24 22:37:02.674: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
09-24 22:37:02.684: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
09-24 22:37:02.704: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
09-24 22:37:02.714: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
09-24 22:37:05.794: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
09-24 22:37:08.434: ERROR/logwrapper(143): executing /system/bin/tc failed: No such file or directory
09-24 22:37:08.895: ERROR/logwrapper(146): executing /system/bin/tc failed: No such file or directory
09-24 22:37:08.994: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
 com.android.providers.telephony.MmsProvider





provider com.android.email.attachmentprovider: com.android.email.provider.AttachmentProvider -> 
09-24 22:39:40.612: ERROR/AndroidRuntime(279): FATAL EXCEPTION: main
09-24 22:39:40.612: ERROR/AndroidRuntime(279): android.content.res.Resources$NotFoundException: String resource ID #0x7
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.content.res.Resources.getText(Resources.java:201)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.widget.TextView.setText(TextView.java:2817)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at app.droidcalc.DroidCalcActivity$15.onclick(DroidCalcActivity.java:180)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.view.View.performClick(View.java:2408)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.view.View$PerformClick.run(View.java:8816)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.os.Looper.loop(Looper.java:123)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 22:39:40.612: ERROR/AndroidRuntime(279):     at dalvik.system.NativeStart.main(Native Method)
09-24 22:39:40.651: WARN/ActivityManager(59):   Force finishing activity app.droidcalc/.DroidCalcActivity
09-24 22:39:41.211: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45065fb8 app.droidcalc/.DroidCalcActivity}
ayed activity app.droidcalc/.DroidCalcActivity: 1132 ms (total 1132 ms)
09-24 22:40:34.872: ERROR/AndroidRuntime(288): FATAL EXCEPTION: main
09-24 22:40:34.872: ERROR/AndroidRuntime(288): java.lang.NumberFormatException: unable to parse '' as integer
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at java.lang.Integer.parseInt(Integer.java:412)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at java.lang.Integer.parseInt(Integer.java:382)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at app.droidcalc.DroidCalcActivity$14.onclick(DroidCalcActivity.java:165)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.view.View.performClick(View.java:2408)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.view.View$PerformClick.run(View.java:8816)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.os.Looper.loop(Looper.java:123)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 22:40:34.872: ERROR/AndroidRuntime(288):     at dalvik.system.NativeStart.main(Native Method)
0 app.droidcalc/app.droidcalc.DroidCalcActivity paused=false}
09-24 22:40:47.391: ERROR/AndroidRuntime(295): FATAL EXCEPTION: main
09-24 22:40:47.391: ERROR/AndroidRuntime(295): android.content.res.Resources$NotFoundException: String resource ID #0x1
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.content.res.Resources.getText(Resources.java:201)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.widget.TextView.setText(TextView.java:2817)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at app.droidcalc.DroidCalcActivity$15.onclick(DroidCalcActivity.java:180)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.view.View.performClick(View.java:2408)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.view.View$PerformClick.run(View.java:8816)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.os.Looper.loop(Looper.java:123)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 22:40:47.391: ERROR/AndroidRuntime(295):     at dalvik.system.NativeStart.main(Native Method)
09-24 22:42:20.522: ERROR/AndroidRuntime(302): FATAL EXCEPTION: main
09-24 22:42:20.522: ERROR/AndroidRuntime(302): android.content.res.Resources$NotFoundException: String resource ID #0x1
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.content.res.Resources.getText(Resources.java:201)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.widget.TextView.setText(TextView.java:2817)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at app.droidcalc.DroidCalcActivity$15.onclick(DroidCalcActivity.java:180)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.view.View.performClick(View.java:2408)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.view.View$PerformClick.run(View.java:8816)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.os.Looper.loop(Looper.java:123)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 22:42:20.522: ERROR/AndroidRuntime(302):     at dalvik.system.NativeStart.main(Native Method)
09-24 22:55:12.091: ERROR/AndroidRuntime(309): FATAL EXCEPTION: main
09-24 22:55:12.091: ERROR/AndroidRuntime(309): android.content.res.Resources$NotFoundException: String resource ID #0x1
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.content.res.Resources.getText(Resources.java:201)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.widget.TextView.setText(TextView.java:2817)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at app.droidcalc.DroidCalcActivity$15.onclick(DroidCalcActivity.java:180)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.view.View.performClick(View.java:2408)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.view.View$PerformClick.run(View.java:8816)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.os.Looper.loop(Looper.java:123)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 22:55:12.091: ERROR/AndroidRuntime(309):     at dalvik.system.NativeStart.main(Native Method)
09-24 23:48:42.663: ERROR/AndroidRuntime(339): FATAL EXCEPTION: main
09-24 23:48:42.663: ERROR/AndroidRuntime(339): java.lang.StringIndexOutOfBoundsException
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at java.lang.String.substring(String.java:1579)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at app.droidcalc.DroidCalcActivity$14.onclick(DroidCalcActivity.java:165)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.view.View.performClick(View.java:2408)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.view.View$PerformClick.run(View.java:8816)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.os.Looper.loop(Looper.java:123)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 23:48:42.663: ERROR/AndroidRuntime(339):     at dalvik.system.NativeStart.main(Native Method)
09-24 23:48:50.612: ERROR/AndroidRuntime(352): FATAL EXCEPTION: main
09-24 23:48:50.612: ERROR/AndroidRuntime(352): java.lang.StringIndexOutOfBoundsException
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at java.lang.String.substring(String.java:1579)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at app.droidcalc.DroidCalcActivity$14.onclick(DroidCalcActivity.java:165)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.view.View.performClick(View.java:2408)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.view.View$PerformClick.run(View.java:8816)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.os.Looper.loop(Looper.java:123)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 23:48:50.612: ERROR/AndroidRuntime(352):     at dalvik.system.NativeStart.main(Native Method)
09-24 23:50:20.151: ERROR/AndroidRuntime(379): FATAL EXCEPTION: main
09-24 23:50:20.151: ERROR/AndroidRuntime(379): android.content.res.Resources$NotFoundException: String resource ID #0x1
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.content.res.Resources.getText(Resources.java:201)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.widget.TextView.setText(TextView.java:2817)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at app.droidcalc.DroidCalcActivity$15.onclick(DroidCalcActivity.java:180)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.view.View.performClick(View.java:2408)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.view.View$PerformClick.run(View.java:8816)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.os.Handler.handleCallback(Handler.java:587)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.os.Looper.loop(Looper.java:123)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at java.lang.reflect.Method.invoke(Method.java:521)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-24 23:50:20.151: ERROR/AndroidRuntime(379):     at dalvik.system.NativeStart.main(Native Method)


Was This Post Helpful? 0
  • +
  • -

#21 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 02:05 AM

Please post you current code.
Was This Post Helpful? 0
  • +
  • -

#22 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 08:16 AM

package app.droidcalc; 

import java.util.ArrayList;

import app.droidcalc.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.text.Editable;

public class DroidCalcActivity extends Activity 
{
    Button one, two, three, four, five, six, seven, 
    eight, nine, zero, clr, bksp, add, sub, mult, eql, deci, div;
    EditText calculations;
    private ArrayList<Integer>numbers;
    
    
	@Override 
	public void onCreate(Bundle savedInstanceState) 
	{ 
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.main); 
		/*val1=(EditText) findViewById(R.id.edVal1); 
		val2=(EditText) findViewById(R.id.edVal2); 
		ans=(TextView) findViewById(R.id.tvAns );*/ 
		calculations=(EditText)findViewById(R.id.calc);
		one=(Button) findViewById(R.id.num1); 
		two=(Button)findViewById(R.id.num2); 
		three=(Button) findViewById(R.id.num3); 
		four=(Button) findViewById(R.id.num4); 
		five=(Button)findViewById(R.id.num5); 
		six=(Button) findViewById(R.id.num6); 
		seven=(Button) findViewById(R.id.num7); 
		eight=(Button)findViewById(R.id.num8); 
		nine=(Button) findViewById(R.id.num9); 
		zero=(Button) findViewById(R.id.button0);
		bksp=(Button) findViewById(R.id.backspace);
		clr=(Button) findViewById(R.id.clear);
		add=(Button) findViewById(R.id.addition);
		sub=(Button) findViewById(R.id.subtraction);
		mult=(Button) findViewById(R.id.multiplication);
		eql=(Button) findViewById(R.id.equalsign);
		deci=(Button) findViewById(R.id.buttonDecimal);
		div=(Button) findViewById(R.id.division);
		
		numbers = new ArrayList<Integer>();
		
		one.setonclickListener(new Button.onclickListener() {
	    @Override
		public void onclick(View v) 
	    {
	       
	    	CharSequence text= one.getText();
			calculations.setText(calculations.getText() + text.toString());		
		}
		});
		
		two.setonclickListener(new Button.onclickListener() {
		@Override
		public void onclick(View v) 
		{
			CharSequence text= two.getText();
			calculations.setText(calculations.getText() + text.toString());  	 
		}
		});
		
		three.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= three.getText();
			calculations.setText(calculations.getText() + text.toString());  	 
		}
		});

		four.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= four.getText();
			calculations.setText(calculations.getText() + text.toString());
		}
		});
		
		five.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= five.getText();
			calculations.setText(calculations.getText() + text.toString());  
		}
		});
		
		six.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= six.getText();
			calculations.setText(calculations.getText() + text.toString());  
		}
		});
		
		seven.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= seven.getText();
			calculations.setText(calculations.getText() + text.toString());      	 
		}
		});
		
		eight.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= eight.getText();
			calculations.setText(calculations.getText() + text.toString());      	 
		}
		});
		
		nine.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= nine.getText();
			calculations.setText(calculations.getText() + text.toString());    	 
		}
		});
		
		zero.setonclickListener(new Button.onclickListener() {
		public void onclick(View v) 
		{
			CharSequence text= zero.getText();
			calculations.setText(calculations.getText() + text.toString());      	 
		}
		});
		
		clr.setonclickListener(new Button.onclickListener(){
		public void onclick(View v)
		{
			EditText calculations=(EditText) findViewById(R.id.calc);
			calculations.setText(" ");
		}
		});	  
		
		deci.setonclickListener(new Button.onclickListener(){
		public void onclick(View v)
		{
			CharSequence text= deci.getText();
			calculations.setText(calculations.getText() + text.toString());
		}
		}); 
		
		bksp.setonclickListener(new Button.onclickListener(){
		@Override
		public void onclick(View v)
		{
			calculations.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
		}
	    });
		
		add.setonclickListener(new Button.onclickListener(){
		@Override
		public void onclick(View v) {
			 numbers.add(Integer.parseInt(calculations.getText().toString().replace(" ", ""))); 
			 calculations.setText(" "); 
		}
		});
		
		eql.setonclickListener(new Button.onclickListener(){
		//@Override
		public void onclick(View v)
		{
			int value = 0;
			for (Integer i : numbers) 
			{
				value += i.intValue();
			}
			calculations.setText(" ");
			calculations.setText(value);
		}
		});
}
}

Was This Post Helpful? 0
  • +
  • -

#23 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 08:44 AM

In "add.setonclickListener" you have calculations.setText(" ");
when there should be calculations.setText("");
Was This Post Helpful? 0
  • +
  • -

#24 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 08:55 AM

I actually thought either way didn't make a difference because the program is still crashing. But I'll check my logcat over again too.
Was This Post Helpful? 0
  • +
  • -

#25 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 09:43 AM

I found the problem and i fixed your code for you. But i did this only for the addition part.
So this code, will only do addition calculations, but it's a start for you.
package app.droidcalc; 
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.text.Editable;

public class DroidCalcActivity extends Activity 
{
    Button one, two, three, four, five, six, seven, 
    eight, nine, zero, add,clr, eql;
    EditText calculations;
    boolean showingequal = false;
    private ArrayList<Integer>numbers;
    String TAG = "Cal";
    
	@Override 
	public void onCreate(Bundle savedInstanceState) 
	{ 
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.main); 
		/*val1=(EditText) findViewById(R.id.edVal1); 
		val2=(EditText) findViewById(R.id.edVal2); 
		ans=(TextView) findViewById(R.id.tvAns );*/ 
		calculations=(EditText)findViewById(R.id.editText1);
		one=(Button) findViewById(R.id.num1); 
		two=(Button)findViewById(R.id.num2); 
		three=(Button) findViewById(R.id.num3); 
		four=(Button) findViewById(R.id.num4); 
		five=(Button)findViewById(R.id.num5); 
		six=(Button) findViewById(R.id.num6); 
		seven=(Button) findViewById(R.id.num7); 
		eight=(Button)findViewById(R.id.num8); 
		nine=(Button) findViewById(R.id.num9); 
		zero=(Button) findViewById(R.id.button0);
		add=(Button) findViewById(R.id.addition);
		clr=(Button) findViewById(R.id.clear);
		eql=(Button) findViewById(R.id.equalsign);
		
		numbers = new ArrayList<Integer>();
		
		one.setonclickListener(listener);
		clr.setonclickListener(listener);
		two.setonclickListener(listener);
		
		three.setonclickListener(listener);

		four.setonclickListener(listener);
		
		five.setonclickListener(listener);
		
		six.setonclickListener(listener);
		
		seven.setonclickListener(listener);
		
		eight.setonclickListener(listener);
		
		nine.setonclickListener(listener);
		
		zero.setonclickListener(listener); 
		
		
		add.setonclickListener(listener);
		
		eql.setonclickListener(listener);
}


	private onclickListener listener = new onclickListener() {

		@Override
		public void onclick(View v) {
			// TODO Auto-generated method stub
			if (calculations.getText().toString() != "") {
			switch(v.getId()) {
			case R.id.num1:
		    	CharSequence text= one.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num2:	
				text= two.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num3:	
				text= three.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num4:	
				text= four.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num5:	
				text= five.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num6:	
				text= six.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num7:	
				text= seven.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num8:	
				text= eight.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.num9:	
				text= nine.getText();
				calculations.setText(calculations.getText() + text.toString());
				break;

			case R.id.button0:
				text= zero.getText();
				calculations.setText(calculations.getText() + text.toString()); 
				break;

			case R.id.addition:
				if (!showingequal)
				 numbers.add(Integer.parseInt(calculations.getText().toString()));
				
				showingequal = false;
				 calculations.setText(""); 
				 break;
				 
			case R.id.clear:
				calculations.setText("");
				numbers = new ArrayList<Integer>();
				break;
				
			case R.id.equalsign:
				numbers.add(Integer.parseInt(calculations.getText().toString()));
				int value = 0;
				Log.d(TAG, numbers.size() + "");
				for (Integer i : numbers) 
				{
					value += i.intValue();
				}
				calculations.setText(value + "");
				showingequal = true;
				break;

			}
			}
			
			
		}
		
	};


}


Hope this works out for you, it works fine for me.

Edit: Seams like DIC's site change some upper letters to lower, that that will give you error.
Check all onclickListener, and each setonclickListener
If they are not as i wrote them there, then change them to exactly that

This post has been edited by EndLessMind: 25 September 2012 - 09:56 AM

Was This Post Helpful? 0
  • +
  • -

#26 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 10:33 AM

I'm getting the error:
The type new View.onclickListener(){} must implement the inherited abstract method View.onclickListener.onclick(View)


at
private onclickListener listener = new onclickListener() 


Do I need to have "View v" or maybe something else between those brackets?
Was This Post Helpful? 0
  • +
  • -

#27 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 10:58 AM

No, the code that i posted works at least down to Android 2.2.
Is the "onclick" with a lower "c"?
If so, change it to a upper "C"
Was This Post Helpful? 0
  • +
  • -

#28 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 11:13 AM

View PostEndLessMind, on 25 September 2012 - 01:58 PM, said:

No, the code that i posted works at least down to Android 2.2.
Is the "onclick" with a lower "c"?
If so, change it to a upper "C"


Mine is an uppercase C. I madeall the other setonclick or onclick ones uppercase as well.
Was This Post Helpful? 0
  • +
  • -

#29 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 11:35 AM

Okey, what you are saying, it that the code i just tested, dose not work.

Here is the exact code i used.
Try to run my project, the apk is in there as well, install it with astro.
You need Android 2.2 to run it.
Attached File  DroidCalc.zip (691.08K)
Number of downloads: 23
Was This Post Helpful? 1
  • +
  • -

#30 izic  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 197
  • Joined: 15-January 09

Re: Having a string of numbers display on click.

Posted 25 September 2012 - 02:06 PM

View PostEndLessMind, on 25 September 2012 - 02:35 PM, said:

Okey, what you are saying, it that the code i just tested, dose not work.

Here is the exact code i used.
Try to run my project, the apk is in there as well, install it with astro.
You need Android 2.2 to run it.
Attachment DroidCalc.zip


Sorry for the hassle, it works fine. Thanks!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2