简体   繁体   English

将字符串转换为整数

[英]Convert string to integer(s)

In my app i have just imported a string to this activity from another activity. 在我的应用程序中,我刚刚从另一个活动将字符串导入了此活动。 I need this string to be converted into 5 integers, the following: 我需要将此字符串转换为5个整数,如下所示:

        int counter1, counter2, counter3, counter4, counter5;

This is my code for receiving the string: 这是我接收字符串的代码:

        Bundle gotBasket = getIntent().getExtras();
        number =  gotBasket.getString("lol");

The string is currently passed successfully, all i need is for it to be converted to integers. 该字符串当前已成功传递,我只需要将其转换为整数即可。

Ad.1. 广告1。 Q

Integer.parseInt(gotBasket.getString("lol"));

Watch out for the NumberFormatException - if the string does not contain a parsable integer. 注意NumberFormatException如果字符串不包含可分析的整数。

Ad.2. 广告2。 Q

ScrollView per each column? 每列是否有ScrollView You really want it that way? 你真的想要那样吗?

Use Integer.parseInt() 使用Integer.parseInt()

EDIT: Or in the first activity attach the extra as an int, then in your new activity use Bundle.getInt() 编辑:或在第一个活动中将附加项附加为int,然后在新活动中使用Bundle.getInt()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM