Android Build an Interactive Story App The Model-View-Presenter Pattern Adding Story Resources

Alan Kuo
Alan Kuo
7,697 Points

I don't understand why we use int variable to get textId and other ids since the value and the id are not integers?

So in the videos, we're using variable int textId to get values from strings.xml, but the both the id and the value are not integers, I don't really understand why we're using int instead of String properties.

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,426 Points

The string resources (and other resources) get integer IDs assigned at compile time. That is where the ints come from. We conveniently use string names in the resource xml files to make it more readable for us. So when we do:

new Choice(R.string.page0_choice1, 1)

The R.string.page0_choice1 value actually becomes an integer, just like we defined in private int textId;

Here's a more detailed answer:

Hope that helps!