【问题标题】:Converting a Spinner to a string and to an integer将 Spinner 转换为字符串和整数
【发布时间】:2014-06-01 16:46:47
【问题描述】:

我有一个微调器的工作方式,一旦选择,它就会转换为字符串,我需要以整数形式将其放回 sqlite 数据库。有谁知道这样做的方法吗?

@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i,long l) {

    Spinner tqo = (Spinner)adapterView;

    if (tqo.getId() == R.id.toq) {
        TextView mytqo = (TextView)view;
        String tow = (String) mytqo.getText();
    }

正如您在上面看到的,我需要整数形式的变量tow,以便我可以使用它。

【问题讨论】:

  • 我的回答对你有用吗?

标签: java android string integer type-conversion


【解决方案1】:

你有一个字符串并且想把它解析成一个整数?您可以使用Integer.parseInt。它将接受一个字符串作为参数并返回该字符串的整数表示。

像这样:

String tow = (String) mytqo.getText();
int towInt = Integer.parseInt(tow);

【讨论】:

    【解决方案2】:

    尝试使用Integer.parseInt() 来获取文本输入的整数等效值。它是纯 Java,应该可以开箱即用。所以你会想要这样的东西:

     int a =  Integer.parseInt(tow);
    

    【讨论】:

      【解决方案3】:

      你能用这样的东西吗:

         int yourVal = Integer.parseInt(tow);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-15
        • 1970-01-01
        • 2012-02-21
        • 2010-12-31
        相关资源
        最近更新 更多