Reputation: 2191
I have table, which is described in main xml layout. I need to know, if there is any chance to set layout to each table row, so I don't need to recreate each time? Where layout is simple, I can do that by code, but at this time layout is pretty complicated.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ebank_saskaitos);
this.setFirstBlock();
}
private void setFirstBlock() {
TableLayout ll = (TableLayout) findViewById(R.id.first_block);
ll.addView(this.tableChild());
}
private TableRow tableChild() {
TableRow tr = new TableRow(this);
//row implementation
return tr;
}
Upvotes: 2
Views: 3804
Reputation: 37729
use LayoutInflater
like this way:
private View tableChild() {
TableRow tr = new TableRow(this);
View v = LayoutInflater.from(mContext).inflate(R.layout.layout_for_my_table_row, tr, false);
//want to get childs of row for example TextView, get it like this:
TextView tv = (TextView)v.findViewById(R.id.my_row_text_view);
tv.setText("This is another awesome way for dynamic custom layouts.");
return v;//have to return View child, so return made 'v'
}
Upvotes: 5