0

从微调器中选择任何数字时,我想要多个字符串值,但问题是 textview 值是字符串'Rs.6,849' 如何将此字符串与任何数字形式的微调器相乘?我很困惑 tet 视图的值来自服务器,所以它不能改变我如何用微调器更改字符串我需要帮助我如何使用微调器整数多个字符串????如何更新每个微调器值选择的文本视图?

         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>
4

2 回答 2

2

您只需要从字符串中提取数字然后相乘。

String value = TextViewprice.getText().toString()
value = value.replaceAll("\\D+",""); //REGEX
multiple = String.valueOf( Integer.parseInt(spn.getSelectedItem().toString())*      Integer.parseInt(value);
于 2013-10-30T07:22:31.263 回答
1
     /**
     * 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;
    }
}
于 2013-10-30T07:38:33.343 回答