Ayush Goyal
Ayush Goyal

Reputation: 2079

Converting string into TextView?

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.

Upvotes: 0

Views: 7275

Answers (2)

jeet
jeet

Reputation: 29199

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

Upvotes: 0

Padma Kumar
Padma Kumar

Reputation: 20031

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

Upvotes: 1

Related Questions