为什么此textId变量是int变量? JAVA Android Stuidio

时间:2018-09-13 06:36:05

标签: java android

所以现在我有一个名为Page的类,它由4个属性组成,分别是 ImageView TextView 和2个按钮

我们试图通过id来获取这4个属性,在textId的情况下,我并不真正理解为什么变量是一个int变量,因为我们吸引的值是一个字符串,而id是某种东西像

R.string.page0

R.string.page1

如果描述有些混乱,请告诉我们。


Page.java:

package com.teamtreehouse.interactivestory.model;

public class Page {
    private int imageId;
    private int textId;
    private Choice choice1;
    private Choice choice2;
    private boolean isFinalPage = false;

    public Page(int imageId, int textId) {
        this.imageId = imageId;
        this.textId = textId;
        this.isFinalPage = true;
    }

    public Page(int imageId, int textId, Choice choice1, Choice choice2) {
        this.imageId = imageId;
        this.textId = textId;
        this.choice1 = choice1;
        this.choice2 = choice2;
    }

    public boolean isFinalPage() {
        return isFinalPage;
    }

    public void setFinalPage(boolean finalPage) {
        isFinalPage = finalPage;
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }

    public int getTextId() {
        return textId;
    }

    public void setTextId(int textId) {
        this.textId = textId;
    }

    public Choice getChoice1() {
        return choice1;
    }

    public void setChoice1(Choice choice1) {
        this.choice1 = choice1;
    }

    public Choice getChoice2() {
        return choice2;
    }

    public void setChoice2(Choice choice2) {
        this.choice2 = choice2;
    }
}

strings.xml:

<resources>
    <string name="app_name">Signals from Mars</string>
    <string name="key_name">name</string>
    <string name="signals_from_mars_title_image">Signals from Mars title image</string>
    <string name="start_your_adventure">START YOUR ADVENTURE</string>
    <string name="enter_your_name">Enter your name</string>

    <string name="page0">On your return trip from studying Saturn\'s rings, you hear a distress signal that seems to be coming from the surface of Mars. It\'s strange because there hasn\'t been a colony there in years. Even stranger, it\'s calling you by name: \"Help me, %1$s, you\'re my only hope.\"</string>
    <string name="page0_choice1">Stop and investigate</string>
    <string name="page0_choice2">Continue home to Earth</string>

    <string name="page1">You deftly land your ship near where the distress signal originated. You didn\'t notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.</string>
    <string name="page1_choice1">Explore the cave</string>
    <string name="page1_choice2">Explore the rover</string>

    <string name="page2">You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.</string>
    <string name="page2_choice1">Head back to Mars to investigate</string>
    <string name="page2_choice2">Continue home to Earth</string>

    <string name="page3">Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there\'s a very faint light up ahead.</string>
    <string name="page3_choice1">Refill at ship and explore the rover</string>
    <string name="page3_choice2">Continue towards the faint light</string>

    <string name="page4">The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren\'t far, but you don\'t know if your oxygen will last for a trip there and back.</string>
    <string name="page4_choice1">Explore the coordinates</string>
    <string name="page4_choice2">Return to Earth</string>

    <string name="page5">After a long walk slightly uphill, you end up at the top of a small crater. You look around, and are overjoyed to see your favorite android, %1$s-S1124. It had been lost on a previous mission to Mars! You take it back to your ship and fly back to Earth.</string>

    <string name="page6">You arrive home on Earth. While your mission was a success, you forever wonder what was sending that signal. Perhaps a future mission will be able to investigate…</string>
    <string name="story_image_content_description">Story page image</string>
    <string name="play_again_button_text">PLAY AGAIN</string>

</resources>

0 个答案:

没有答案