将微调器转换为字符串和整数

时间:2014-06-01 16:46:47

标签: java android string integer type-conversion

我有一个微调器以这样的方式工作,一旦被选中,就转换为一个字符串,我需要以整数形式将其放回到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,以便我可以使用它。

3 个答案:

答案 0 :(得分:3)

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

像这样:

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

答案 1 :(得分:1)

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

 int a =  Integer.parseInt(tow);

答案 2 :(得分:-1)

你能用这样的东西:

   int yourVal = Integer.parseInt(tow);