Reputation: 888
I am developing an android app. I need to populate my list with images. I want to insert image in table layout row by row using array. Can you guide me how to do it? Thank you.
Upvotes: 1
Views: 8015
Reputation: 86
Use this code and make changes according to your code
TableLayout table = new TableLayout(this);
for (int i = 0; i < mRows; i++) {
TableRow tr = new TableRow(mContext);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
for (int j = 0; j < mCols; j++) {
ImageView view = new ImageView(this);
view.setImageResource(R.drawable.star_on)
tr.addView(view);
}
table.addView(tr);
}
Upvotes: 6