2016-08-26 2 views
0

私はrowTextView.setText(" row value #" + str);を設定し、arraylistの最後の値を表示するたびにarraylistデータを設定します。 私のリストデータは60,65,70,75,80です。すべてのデータが必要です。これはどうすれば実現できますか?このダイナミックテキストビューでarraylistデータを設定する方法

int size = al_getAllProductSize.size(); 
TextView[] myTextViews = new TextView[size]; 
for (int i = 0; i < size; i++) { 
    myTextViews[i] = new TextView(MainActivity.this); 
    rowTextView.setText(al_getAllProductSize.get(i)); 
    ll_textViewObj.addView(myTextViews[i]); 
    } 
+1

すべてのArrayListデータを1つのテキストビューに追加しますか? – Dentor

+0

良いアプローチのための@Dentor 5 textviewのための別のtextview.5データ – Kankana

+0

@Dentor単一のテキストビュー可能?? – Kankana

答えて

1

、あなたのようなものを使用することができます。それがあなたを助けることを願ってください。

final int X = 5; // total number of textviews to add 
final TextView[] myTextViews = new TextView[X]; // create an empty array; 

for (int i = 0; i < X; i++) { 
     // create a new textview 
      final TextView rowTextView = new TextView(this); 

     // set value in textview 
      rowTextView.setText("row value #" + i); 

     // add the textview to the linearlayout 
      ll_textViewObj.addView(rowTextView); 

     // save a reference to the textview for later 
      myTextViews[i] = rowTextView; 
} 
+0

はい.worked。#al_getAllProductSize.get(i) – Kankana

+0

この問題を解決するには – Kankana

0

:あなたは、各のTextViewの各文字列をしたい場合は

int size = al_getAllProductSize.size(); 

      System.out.println("The size of array is: " + size); 
      for (int i = 0; i < size; i++) { 


      } 

      final int N = 5; // total number of textviews to add 

      final TextView[] myTextViews = new TextView[N]; // create an empty array; 

      for (int i = 0; i < N; i++) { 
      final TextView rowTextView = new TextView(MainActivity.this); 

      for (String str : al_getAllProductSize) 
      { 

      rowTextView.setText(" row value #" + str); // i want all value through loop 

       } 

       ll_textViewObj.addView(rowTextView); 

       // save a reference to the textview for later 
       myTextViews[i] = rowTextView; 
      } 
+0

両方がうまくいきます。私はあなたの答えをupvote – Kankana

+0

問題は、それが助けてくれることを願って – Dentor

+0

私は低い担当者を持っています。それはなぜあなたの答えをupvoteすることができません。 – Kankana

1

はこの1つを試してみ

for (int i = 0; i < N; i++) { 
    final TextView rowTextView = new TextView(MainActivity.this); 

    // getting respective string val from list 
    rowTextView.setText(" row value #" + al_getAllProductSize.get(i)); 

    ll_textViewObj.addView(rowTextView); 

    // save a reference to the textview for later 
    myTextViews[i] = rowTextView; 
} 
関連する問題