• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Table layout programatically

pecmcrl

Lurker
Sep 1, 2011
2
0
Hi.......i am new to android development.. Iam trying to create a table layout programatically in the activity it self without using xml file........ Please help to know can i do it.

Can anyone find the error in following code.....

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Tablelayout extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

TextView tv=new TextView(this);
tv.setLayoutParams(params);
tv.setTextColor(Color.RED);

TableRow tr=new TableRow(this);
tr.addView(tv);

TableLayout tl=new TableLayout(this);
TableLayout.LayoutParams layoutparams=new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tl.addView(tr);

this.addContentView(tl, layoutparams);
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones