String数组列表显示的问题 [英] String array list display problem

查看:161
本文介绍了String数组列表显示的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建String数组一个是字,一个是一句话。

I have create to String array one is "word" another is "sentence".

   <resources>
<string-array name="word">
         <item> the</item>
         <item> a</item>
         <item> is</item>
         <item> you</item>
         <item> to</item>
      </string-array>
 <string-array name="sentence">
         <item> the little boy</item>
         <item> a good boy</item>
         <item> is about me</item>
         <item> then you give</item>
         <item> was to come</item>
    </string-array>
   </resources>

现在我试图访问从Java code这两个字符串数组。这是

Now i am trying access these two string array from the java code. which is

    final String  words []=getResources().getStringArray(R.array.word);
    final TextView tw=(TextView)findViewById(R.id.txtWord);
    tw.setText(words [item]);


    final   String []sent=getResources().getStringArray(R.array.sentence);
    TextView ts=(TextView)findViewById(R.id.txtSen);
    ts.setText(sent[item]);

    Button btnNext=(Button)findViewById(R.id.btnright);
    btnNext.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            for(item=0;item<words.length;item++){
            tw.setText(words [item]);


            for(item=0;item<sent.length;item++){
            tw.setText(sent[item]);}
                               }
        }

               });
           }
     }

Iniailly话是地方显示的话阵列和句子的地方,显示句阵列,所以不要被迷惑。
在这里,我的本意是一次显示所有上述五个项目一个项目如果我点击上图中的下一个(>>)按钮,只改变单词和句子同时进行。但只字[0]和发送[0]为显示。第一次,但不能没有显示,如果点击>>按钮,把它转化为显示A和好孩子各自的位置。
你有这个问题背后的想法?也想从底层改变指数|左上角指数。如果我点击下一个单词和句子。

Iniailly Word is place to display words array and Sentence is place to display sentence array so dont be confuse. Here my intention is to display all above five item one item at a time only change word and sentence simultaneously if i click the next(>>) button above figure. but only word[0] and sent[0] was display. first time but cant not display if click >> button, which it turn to display "a" and "a good boy" respective position. Do you Have any idea behind this problem? Also want to change index from the bottom|left corner index. if i click next word and sentence.

推荐答案

做这样为下

btnNext.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
            item++;
            item=item%words.length(); 
            tw.setText(words [item]);



        }

               });

这篇关于String数组列表显示的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆