0

DBからすべてのエントリを文字列として取得するArrayListがあります

List<Amthal> amthal = getAmthalSetFromDb(p);

「含まれている文字列の数」のサイズを取得できます

int i= amthal.size();

次のボタンをクリックして次の文字列に移動することにより、これらの文字列をTextViewで次々に表示したい

その配列リスト内の任意の文字列を表示しようとしましたが、エラーが発生しました…「get(i-1)」。この配列の最後の文字列を返す必要があります…</ p>

    tv.setText(amthal.get(i-1));

私の質問は、これらの文字列を取得して表示する方法ですか?文字列の配列に変換する必要がありますか?

4

1 に答える 1

0

次のようなカウンター変数を使用して、問題を解決できます。

public static int count=0;  //Declare it as class level varaible
yourbutton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

    if(count < amthal.size())
         {
              tv.setText(amthal.get(count).toString()); //set textView Text here
              count++;  // increase counter here
         }
         else{
            //Reset counter to 0
          }
    }
});
于 2012-11-25T14:32:30.097 に答える