[android-beginners] Re: EditText to String to int

2008-04-24 Thread Dan U.

Don't worry about it. It's like writing a resume or some other
document. You sometimes need someone to proofread what you write and
sometimes you miss the most obvious things.

On Apr 24, 6:50 pm, Kyle <[EMAIL PROTECTED]> wrote:
> Oh my god... You know Dan, you've been a great sport to me, I can't
> thank you enough, I should really open my eyes a little more, I'm so
> very sorry for wasting your time, haha, I feel incredibly stupid...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: EditText to String to int

2008-04-24 Thread Kyle

Oh my god... You know Dan, you've been a great sport to me, I can't
thank you enough, I should really open my eyes a little more, I'm so
very sorry for wasting your time, haha, I feel incredibly stupid...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: EditText to String to int

2008-04-24 Thread Dan U.

You said "edittext", but what is edittext? It sounds like the name
you've given to an EditText, but I see btnAddCost.getText().toString()
which kinda makes me wonder if it's really a button you are trying to
get the text from. Are you sure that value is a number?

On Apr 24, 6:21 pm, Kyle <[EMAIL PROTECTED]> wrote:
> Ok I rearranged my code a bit and put the triggered code into public
> voids. Here is the code that fires my function:
>
> final String value = btnAddCost.getText().toString();
> addCost(Integer.parseInt(value));
>
> and here is the addCost() function:
>
> public int totalCost=0;
>
> public void addCost(int cost)
> {
> final TextView txtTotalCost;
>
> txtTotalCost = (TextView) findViewById(R.id.txtTotalCost);
>
> totalCost = totalCost + cost;
> txtTotalCost.setText("$"+totalCost);
>
> }
>
> this all compiles fine, has no errors, and no warnings; yet when I
> enter a valid integer, (edittext is numeric only) it crashes the app.
> Any ideas? I don't really know how to use the debugger yet.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: EditText to String to int

2008-04-24 Thread Kyle

Ok I rearranged my code a bit and put the triggered code into public
voids. Here is the code that fires my function:

final String value = btnAddCost.getText().toString();
addCost(Integer.parseInt(value));

and here is the addCost() function:

public int totalCost=0;

public void addCost(int cost)
{
final TextView txtTotalCost;

txtTotalCost = (TextView) findViewById(R.id.txtTotalCost);

totalCost = totalCost + cost;
txtTotalCost.setText("$"+totalCost);
}

this all compiles fine, has no errors, and no warnings; yet when I
enter a valid integer, (edittext is numeric only) it crashes the app.
Any ideas? I don't really know how to use the debugger yet.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: EditText to String to int

2008-04-24 Thread Dan U.

The message seems a bit different from what I'd expect, but I think
it's a matter of using final. Final for a primitive means you can't
change it (and if it were an object, it means you can't reassign to a
different object, but you can change the internal state of it). So,
probably define totalCost as a member variable of your class and drop
the final keyword.

On Apr 24, 5:24 pm, Kyle <[EMAIL PROTECTED]> wrote:
> Hi, I've been looking for a way of doing this, maybe it's just my lack
> of thought, or maybe I'm just too noob at Java, but I'm trying to get
> EditText text (can do this), send to a string (can also do this)
> convert to int, add to a global int, and then write the global int to
> a TextView. Here is my code:
>
> final int totalCost=0;
> btnAddCost.setOnClickListener(new Button.OnClickListener() {
> public void onClick(View v) {
> final String value = btnAddCost.getText().toString();
> totalCost = Integer.parseInt(value);
> txtTotalCost.setText("$"+totalCost);
> }
> });
>
> Eclipse returns an error saying:
> The final local variable totalCost cannot be assigned, since it is
> defined in an enclosing type
>
> Any ideas? Basically what it is, is a price updater, adds the amount
> of money you typed in, to the TextView (txtTotalCost)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---