Reputation: 220
I have a list of bitmap images, How can I add this bitmap to a tableLayout programmatically?
thanks.
Upvotes: 0
Views: 7170
Reputation: 3044
Try something like this:
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);
}
This generates the whole table / grid programmatically. You can see how it instantiates an ImageView and sets the image.
Upvotes: 6