1

in my Android app I have a set of string array values - tvs[1], tvs[2], tvs3[3], etc., which contain the textview value from a number of Number Pickers. However, I need the Integer value of each of these strings, so I can then multiply this numeric value with the unit cost of various meals. ie 4 x burgers, 3 x chips, etc. How do I go about this process? I've looked at other questions, but can't find the answer. Can anyone suggest a solution? ie int Value = .....(tvs[1]

2 Answers 2

2

you can simply convert your whole string array to integer array.

int[] integersArray = new int[stringArray.length];
for(int i = 0;i < stringArray.length;i++){
   integersArray [i] = Integer.parseInt(stringArray[i]);
}
Sign up to request clarification or add additional context in comments.

Comments

1

This is just one of many ways on how to convert a String to int.

int a = Integer.valueOf(string);

15 Comments

Thanks - but what is the syntax for using this, say, in a Toast ie using tvs[1]
This is what I have at the moment: result.append(tvs[1].getText().toString() + "x" + "\nHaddock(Med) 50Rs"); - but I want to multiply the 50Rs by the integer value from the string array element tvs[1]
total += Integer.valueOf(tvs[1].getText().toString()) * 50
Hi again! Your answer worked prefectly - one more query (final one!) - how do I add the BigDecimal totalamount1 to totalamount+= , as below.
BigDecimal bd = new BigDecimal("4.4"); BigDecimal value = new BigDecimal (Integer.valueOf(tvs[1].getText().toString())); BigDecimal totalamount1 = value.multiply(bd); totalamount+= totalamount1;
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.