gaurav tiwari gaurav tiwari - 1 year ago 84
Android Question

Add single quotes after an array element

I am converting centimeters into feet inches and wanted to display in standard format with quotes. I am able to get feet and inches separately in an array but stuck in appending quotes.

Output format required is


Here is my code:

private void convertTofeetInches(EditText height_cm){
String str = height_cm.getText().toString();
float result = (Float.valueOf(str)/3);
String[] arr=String.valueOf(result).split("\\.");
int[] intArr=new int[2];
intArr[0]=Integer.parseInt(arr[0]); // feet
intArr[1]=Integer.parseInt(arr[1]); // inches
int count = intArr.length;

Answer Source

Set value on text and add quote at start because intArr[0] is Integer value

textview.setText (""+intArr[0] + " ft, " +  intArr[1] + " inches");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download