user2931692
user2931692

Reputation: 17

My code doesn't multiply value of string with integer

I want to multiple string value when select any number from spinner but problem is textview value is string 'Rs.6,849' how do I multiply this string with any number form spinner? I'm soconfuse value off tet view is come from server so it cant change how I can change string with spinner I need help on how do I multiple string with spinner integer???? How to update textview on each spinner value select?

         TextViewprice =( "Rs.6,849") ;
        TextViewprice = (TextView) findViewById(R.id.TextViewprice);

             spn = (Spinner) findViewById(R.id.spnner);
            spn.setOnItemSelectedListener(new OnItemSelectedListener()
            {

    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
      String multiple;
              multiple= 
      String.valueOf( Integer.parseInt(spn.getSelectedItem().toString())*
               Integer.parseInt(TextViewprice.getText().toString()));


               {
                  T
       extViewprice.setText(multiple);
               }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }

             });  


   <Spinner
    android:id="@+id/spnner"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
       android:layout_marginRight="10dp"
    android:layout_width="wrap_content"
    android:entries="@array/feedbacktypelist"></Spinner>




              <string-array name="feedbacktypelist">
            <item>1</item>
            <item>2</item>
            <item>3</item>
            <item>4</item>
            <item>5</item>
            <item>6</item>

            <item>7</item>
            <item>8</item>
             <item>9</item>
              <item>10</item>
     </string-array>

Upvotes: 0

Views: 1120

Answers (2)

Vasanth
Vasanth

Reputation: 6385

     /**
     * Convert Currency To Double.
    */
public static Double convertCurrencyToInteger(String strNumber) {

    try {

        // Split "Rs." from string.
        strNumber = strNumber.substring(3, strNumber.length());

        // Convert String to Number.
        Double number = NumberFormat.getNumberInstance().parse(strNumber)
                .doubleValue();

        return number;
    }

    catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

Upvotes: 1

Gaurav Bhor
Gaurav Bhor

Reputation: 1157

You need to extract only digits from the string and then multiply.

String value = TextViewprice.getText().toString()
value = value.replaceAll("\\D+",""); //REGEX
multiple = String.valueOf( Integer.parseInt(spn.getSelectedItem().toString())*      Integer.parseInt(value);

Upvotes: 2

Related Questions