Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何调用新的字符串数组_Android_Arrays_String - Fatal编程技术网

Android 如何调用新的字符串数组

Android 如何调用新的字符串数组,android,arrays,string,Android,Arrays,String,我有一个TextView、一个EditView、一个Submit按钮和一个next按钮。在我的资源文件中,我有3个字符串数组。如果EditText中的答案是第一个字符串数组的正确答案,我想转到第二个字符串数组(下一步按钮)。同样,如果我在EditText中的答案是第二个字符串数组的正确答案,我想转到第三个字符串数组(下一步按钮),依此类推。下面是我的代码。这怎么可能呢。在person2之后,返回到person1。有什么更好的方法?有人能举个例子吗。谢谢 //字符串数组 <string-ar

我有一个TextView、一个EditView、一个Submit按钮和一个next按钮。在我的资源文件中,我有3个字符串数组。如果EditText中的答案是第一个字符串数组的正确答案,我想转到第二个字符串数组(下一步按钮)。同样,如果我在EditText中的答案是第二个字符串数组的正确答案,我想转到第三个字符串数组(下一步按钮),依此类推。下面是我的代码。这怎么可能呢。在person2之后,返回到person1。有什么更好的方法?有人能举个例子吗。谢谢

//字符串数组

<string-array name="person1">
    <item>He wore a black hat</item>
    <item>He's six feet tall</item>
    <item>He went to Harvard</item>
    <item>Moon</item>
</string-array>

<string-array name="person2">
    <item>She has a cooking show</item>
    <item>Her dogs name is Max</item>
    <item>She drives a red car</item>
</string-array>

<string-array name="person3">
    <item>He first appeared on a drama</item>
    <item>He's a friend of yours</item>
    <item>His hair is red</item>
</string-array>


他戴着一顶黑帽子
他有六英尺高
他上的是哈佛大学
月亮
她有一个烹饪表演
她的名字叫马克斯
她开一辆红色的车
他第一次出现在一部戏剧中
他是你的朋友
他的头发是红色的

//主要活动

public class MainActivity extends AppCompatActivity {

    int mCounter= 0;
    int aCount = 0;
    int bCount = 0;
    TextView myTv;
    Button nextBtn;
    Button submitBtn;
    EditText msg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        nextBtn = (Button)findViewById(R.id.nextBtn);
        myTv = (TextView)findViewById(R.id.myTv);
        msg = (EditText)findViewById(R.id.msg);

        final String[]person1 = getResources().getStringArray(R.array.person1);
        final String[]person2 = getResources().getStringArray(R.array.person2);
        final String[]person3 = getResources().getStringArray(R.array.person3);
        nextBtn.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        myTv.setText(person1[mCounter]);

                        if (mCounter < person1.length -1){
                            mCounter++;
                        }else {
                            mCounter = 0;
                        }
                        if(msg.getText().toString().trim().toLowerCase().equals("MARK".toString().trim().toLowerCase())){

                            myTv.setText(person2[aCount]);

                            if (aCount < person2.length -1){
                                aCount++;
                            }else {
                                aCount = 0;
                            }
                            if (msg.getText().toString().trim().toLowerCase().equals("Susan".toString().trim().toLowerCase())){

                                myTv.setText(person3[bCount]);

                                if (bCount < person3.length -1){
                                    bCount++;
                                }else {
                                    bCount = 0;
public类MainActivity扩展了AppCompatActivity{
int mCounter=0;
int aCount=0;
int bCount=0;
TextView-myTv;
按钮nextBtn;
按钮提交tn;
编辑文本消息;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nextBtn=(按钮)findViewById(R.id.nextBtn);
myTv=(TextView)findviewbyd(R.id.myTv);
msg=(EditText)findViewById(R.id.msg);
最后一个字符串[]person1=getResources().getStringArray(R.array.person1);
最后一个字符串[]person2=getResources().getStringArray(R.array.person2);
最后一个字符串[]person3=getResources().getStringArray(R.array.person3);
nextBtn.setOnClickListener(
新建视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
myTv.setText(person1[mCounter]);
如果(mCounter
您遇到了什么错误?将person1、2、3对象放入另一个数组中,然后在按“下一步”时对其进行迭代。当person 2的答案正确(Susan)后,当我单击“下一步”而不是单击person 3时,它将返回到person 1。我能够找到它。thx。