简体   繁体   中英

Android: set xml layout to table row?

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

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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM