简体   繁体   中英

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:

        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. Q

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

Watch out for the NumberFormatException - if the string does not contain a parsable integer.

Ad.2. Q

ScrollView per each column? You really want it that way?

Use Integer.parseInt()

EDIT: Or in the first activity attach the extra as an int, then in your new activity use Bundle.getInt()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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