In my android project, I had a table view and I want to add some image buttons dynamically. So I code like this
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
TableRow rows = new TableRow(this);
rows.setBackgroundColor(Color.parseColor("#eaeaea"));
rows.setId(4500+id);
ImageButton btns=new ImageButton(this);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params1.leftMargin = 10;
params1.bottomMargin = 10;
btns.setBackgroundResource(R.drawable.accept);
btns.setId(id);
btns.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int id=v.getId();
setFlag(id);
}
});
LinearLayout childLayout = new LinearLayout(context);
childLayout.addView(btns);
rows.addView(childLayout);
table.addView(rows);
Its working fine. But the number of image buttons may vary. Sometimes 5-10 buttons That time all the buttons are showing in a single row. I want to expand the linearlayout and tablerow layout according to the buttons like the image.
Any idea for that ?
I am new to android please help
Thanks in advance