0

Have a look at this code:

ArrayList<Object> row = data.get(position);

TextView idText = new TextView(this);
idText.setText(row.get(0).toString());
tableRow.addView(idText);

TextView storeText = new TextView(this);
idText.setText(row.get(1).toString());
tableRow.addView(storeText);

TextView maggiText = new TextView(this);
idText.setText(row.get(2).toString());
tableRow.addView(maggiText);

I have to manually create a TextView, set it to some string and then pass it. Is there a way by which I can directly pass the string to row that can be put in a for loop?

I am looking for this approach for scalability issues.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
Ayush Goyal
  • 2,079
  • 8
  • 32
  • 47
  • Sounds like an [ArrayAdapter](http://developer.android.com/reference/android/widget/ArrayAdapter.html) is what you need. You can overwrite `getView()`. – David Aug 03 '12 at 09:53

2 Answers2

1

///you did mistake while copy paste

//idText using in all Tv

let do it as below

TextView idText = new TextView(this);
        idText.setText(row.get(0).toString());
        tableRow.addView(idText);

        TextView storeText = new TextView(this);
        storeText.setText(row.get(1).toString());
        tableRow.addView(storeText);

        TextView maggiText = new TextView(this);
        maggiText.setText(row.get(2).toString());
        tableRow.addView(maggiText);
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
0

ArrayList row = data.get(position);

for(int i=0; i<row.size(); i++)
{
    TextView text= new TextView(this);
    idText.setText(row.get(i).toString());
    tableRow.addView(idText);
}
jeet
  • 29,001
  • 6
  • 52
  • 53
  • you arent creating three components in a row, instead you are creating a single textview, and appending three strings to it. – jeet Aug 03 '12 at 10:03