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

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

问题描述

我创建了字符串数组,一个是词",另一个是句子".

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 代码访问这两个字符串数组.这是

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 Word 是显示单词数组的地方,Sentence 是显示句子数组的地方,所以不要混淆.这里我的目的是一次显示所有以上五个项目,如果我单击上图的下一步(>>)按钮,则一次只同时更改单词和句子.但只显示 word[0] 和 sent[0].第一次点击>>按钮不显示,依次显示a"和a good boy"各自的位置.你对这个问题有什么想法吗?还想从下|左角索引更改索引.如果我点击下一个单词和句子.

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]);



        }

               });

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

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