Jim Thornton
Jim Thornton

Reputation: 123

How to take user inputted number and assign to byte

I've got a user input dialog box which I'm using to update a value.

byte valScoreAway = 0;

The value of valScoreAway is displayed on the screen with:

tvScoreAway.setText( valScoreAway );

This works perfectly.

During the program the score will increment when the TextView tvScoreAway is clicked. This works perfectly.

If there is an error, I have it so that a onLongClickListerner() will inflate a dialog box with an edit field. The user will enter the correct value into the EditView and then click OK. When the OK button is click, I am trying to assign the user inputted value to valScoreAway but it is failing because valScoreAway is a byte type and userInput.getText() is returning a string.

Basically, I need to convert the value of userInput.getText() to a byte type.

Can someone please help me with this?

Upvotes: 1

Views: 112

Answers (4)

mihirjoshi
mihirjoshi

Reputation: 12201

userInput.getText().toString().getBytes(); 

//convert string to byte

Upvotes: 1

RajeshVijayakumar
RajeshVijayakumar

Reputation: 10620

You can convert a edit text input to byte type. By using the following way :

String example = userInput.getText().toString();
example.getBytes();

Upvotes: 2

eppesuig
eppesuig

Reputation: 1385

Why don't you use Integer.parseInt(userInput.getText())? See http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html

Upvotes: 0

Android Killer
Android Killer

Reputation: 18499

Byte.parseByte(userInput.getText().toString());

Upvotes: 3

Related Questions