How to add rows in table of android - java

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/myImView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="#drawable/image1" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="#+id/myTable"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
</LinearLayout>
I want to add n-rows in table "myTable" at run time what should i do ?
currently i am using this code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout myTable = (TableLayout) findViewById(R.id.myTable);
TextView tv = new TextView(this);
for (int x = 0; x < 5; x++) {
tv.setText("This is row number=" + (x + 1));
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(tv);
myTable.addView(tr, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
}
}
but it is giving me this error
03-26 00:29:34.070:
E/AndroidRuntime(2230): java.lang.RuntimeException: Unable to start activity ComponentInfo{assignment.1/assignment.1.myView}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout myTable = (TableLayout) findViewById(R.id.myTable);
for (int x = 0; x < 5; x++) {
TextView tv = new TextView(this);
tv.setText("This is row number=" + (x + 1));
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(tv);
myTable.addView(tr, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
}
}
Try now a small and minor change

I guess this is because you are creating the row object new every time in your loop, but you dont do this with the TextView Object.
Like this it should work:
TableLayout myTable = (TableLayout) findViewById(R.id.myTable);
TextView tv;
TableRow tr;
for (int x = 0; x < 5; x++) {
tv = new TextView(this);
tv.setText("This is row number=" + (x + 1));
tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(tv);
myTable.addView(tr, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
}

Related

Can't duplicate layout look in XML resource file through Java

I'm new to Android development. I searched the web for an answer, but coming up empty. I'm trying to create rows in a TableLayout dynamically that looks like what I have in my XML below:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context="com.example.me.testdesign.MainActivity">
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="368dp"
android:layout_height="345dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView10"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#12dd12"
android:text="static textview"
android:textSize="12sp"
android:layout_marginRight="10dp"/>
<Button
android:id="#+id/button8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="static btn"
android:textSize="12sp"
android:background="#12dd12"/>
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>
This XML file gives the look I want for each row, as pictured in the snapshot below:
Below is the Java code to create an additional row dynamically:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show(); }
});
TableLayout.LayoutParams tvlparams =
new TableLayout.LayoutParams(0, TableLayout.LayoutParams.MATCH_PARENT);
tvlparams.weight = 3;
TextView tv = new TextView(this);
tv.setBackgroundColor(0xff12dd12);
tv.setText("dynamic textview");
tv.setLayoutParams(tvlparams);
TableLayout.LayoutParams btnlparams =
new TableLayout.LayoutParams( 0, TableLayout.LayoutParams.MATCH_PARENT);
btnlparams.weight = 2;
btnlparams.rightMargin = 10;
Button btn = new Button(this);
btn.setText("dynamic btn");
btn.setBackgroundColor(0xff12dd12);
btn.setLayoutParams(btnlparams);
TableRow row = new TableRow(this);
row.addView(tv);
row.addView(btn);
TableLayout TL = (TableLayout) findViewById(R.id.tableLayout);
TL.addView(row);
}
}
The Java code above seems to do nothing! Why don't I get a new row?
However if I comment out tv.setLayoutParams(tvlparams) and btn.setLayoutParams(btnlparams) I get this:
What is going on? What am I doing wrong? Thanks.
This should work for you:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* create textview */
TextView tv = new TextView(this);
tv.setBackgroundColor(0xff12dd12);
tv.setText("dynamic textview");
/* create button */
Button btn = new Button(this);
btn.setText("dynamic btn");
btn.setBackgroundColor(0xff12dd12);
TableRow.LayoutParams trparams = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT);
trparams.weight = 3;
tv.setLayoutParams(trparams);
trparams.weight = 2;
trparams.rightMargin = 10;
btn.setLayoutParams(trparams);
TableLayout tableLayout = (TableLayout) findViewById(R.id.layoutTable);
LinearLayout.LayoutParams tableRowParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
/* create a table row */
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(tableRowParams);
/* add views to the row */
tableRow.addView(tv);
tableRow.addView(btn);
/* add the row to the table */
tableLayout.addView(tableRow);
}

How to add below layout programatically

I have below layout in xml. But I want to add few more similar rows(RelativeLayouts one below another) dynamically with same layout. I've tried the below code, but all the values are overlapping.
Also I don't know how to add textview one below another programmatically.
Any help in solving this would be helpful. Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ccc">
<LinearLayout
android:id="#+id/searchResultsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#fff"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_height="100dp"
android:padding="6dip" >
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:ellipsize="marquee"
android:text="Ali Connors"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:gravity="center_vertical"
android:text="Brunch this weekend?"
android:textSize="12sp" />
<TextView
android:id="#+id/rightTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="15m"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Code:
LinearLayout ll = (LinearLayout) findViewById(R.id.searchResultsLayout);
for (int i = 0; i <1; i++) {
RelativeLayout row= new RelativeLayout(this);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
relativeParams.setMargins(20, 5, 20, 5);
row.setBackgroundColor(Color.parseColor("#ffffff"));
ll.setLayoutParams(relativeParams);
TextView name = new TextView(this);
TextView time = new TextView(this);
TextView dest = new TextView(this);
name.setText("Name");
time.setText("9hrs");
dest.setText("Destination");
row.addView(name);
row.addView(time);
row.addView(dest);
ll.addView(row,i);
}
just replace your code with below code:
here is java code
setContentView(R.layout.myview_activity);
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
for (int i = 0; i <5; i++) {
LinearLayout row= new LinearLayout(this);
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(20, 5, 20, 5);
row.setLayoutParams(layoutParams);
row.setBackgroundColor(Color.parseColor("#000000"));
LinearLayout.LayoutParams layoutParams1=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams1.setMargins(0,0,20,0);
TextView name = new TextView(this);
name.setLayoutParams(layoutParams1);
TextView time = new TextView(this);
time.setLayoutParams(layoutParams1);
TextView dest = new TextView(this);
dest.setLayoutParams(layoutParams1);
name.setText("Name");
time.setText("9hrs");
dest.setText("Destination");
row.addView(name);
row.addView(time);
row.addView(dest);
ll.addView(row);
}
}
LinearLayout ll = (LinearLayout) findViewById(R.id.searchResultsLayout);
ll.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i <1; i++) {
RelativeLayout row= new RelativeLayout(this);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
relativeParams.setMargins(20, 5, 20, 5);
row.setBackgroundColor(Color.parseColor("#ffffff"));
ll.setLayoutParams(relativeParams);
TextView name = new TextView(this);
TextView time = new TextView(this);
TextView dest = new TextView(this);
final RelativeLayout.LayoutParams paramsval =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
name.setText("Name");
name.setId(View.generateViewId());
time.setText("9hrs");
dest.setText("Destination");
time.setLayoutParams(layoutParams);
row.addView(time);
row.addView(name);
paramsval.addRule(RelativeLayout.BELOW,name.getId());
dest.setLayoutParams(paramsval);
row.addView(dest);
ll.addView(row,i);
}
in order to get relative Layout one below other just use listview and adapter. it will automatically generate when you get data

row generator with textviews

This is my code for a n app in which i want to add textviews in a row
dynamically on click of a button and not working can you tell me whats wrong with the code,i am just a beginner.
thanking you in anticipation.
public class MainActivity extends AppCompatActivity {
Button save;
TableLayout tableLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button save = (Button) findViewById(R.id.save);
TableLayout tableLayout = (TableLayout) findViewById(R.id.table1);
save.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
TableRow tableRow;
TextView textView;
TableLayout tableLayout = (TableLayout) findViewById(R.id.table1);
for (int i = 0; i < 4; i++) {
tableRow = new TableRow(getApplicationContext());
for (int j = 0; j < 3; j++) {
textView = new TextView(getApplicationContext());
textView.setText("####");
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
}
tableLayout.addView(tableRow);
}}});
setContentView(tableLayout);
}
}
and my xml layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.kalla.monu.saplist.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="28dp"
android:layout_marginTop="160dp"
android:id="#+id/table1"
android:background="#color/colorPrimaryDark">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#android:color/holo_green_dark" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:id="#+id/save" />
</RelativeLayout>
Try this,
I assume you are trying to add tablerows and textviews both dynamically. So I have removed existing tablerows from layout xml.
TableLayout tableLayout = (TableLayout) findViewById(R.id.table1);
save.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
TableRow tableRow;
TextView textView;
for (int i = 0; i < 4; i++) {
tableRow = new TableRow(this);
for (int j = 0; j < 3; j++) {
textView = new TextView(this);
textView.setText("####");
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
}
table1.addView(tableRow);
}}});
In XML:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/table1"/>

how to put dynamic TableRow in TableLayout and place Textview dynamically in TableRow using Android?

i am newbie and facing difficulty to achieve my required output.
XML CODE:
//this code is inside of ScrollView
<LinearLayout
android:id="#+id/statusSecond_Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="#+id/statusDisciplineTable_layout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
></TableLayout>
</LinearLayout>
JAVA CODE:
setContentView(R.layout.status_view);
statusTableLayout = (TableLayout)findViewById(R.id.statusDisciplineTable_layout);
for(int i=0;i<2;i++)
{
TableRow statusTableRow = new TableRow(this);
statusTableRow.setId(i);
statusTableRow.setOrientation(TableRow.VERTICAL);
TextView productsTextView = new TextView(this);
productsTextView.setText("product name:"+i);
statusTableRow.addView(productsTextView);
//statusTableRow.setBackgroundColor(Color.BLACK);
for(int j=0;j<2;j++)
{
RelativeLayout statusRelativelayout = new RelativeLayout(this);
TableRow.LayoutParams rlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
rl.setMargins(0, 0, 16, 0);
rl.addRule(RelativeLayout.ALIGN_LEFT);
TextView label = new TextView(this);
label.setId(j);
label.setText("abcd:"+j);
label.setLayoutParams(rl);
statusRelativelayout.addView(label);
statusTableRow.addView(statusRelativelayout,rlp);
}
statusTableLayout.addView(statusTableRow);}
please tell me what should i need to do changes in my current code to product required given image
You can use LinearLayout instead of TableRow like this
TableLayout statusTableLayout = (TableLayout)findViewById(R.id.statusDisciplineTable_layout);
for(int i=0;i<2;i++)
{
LinearLayout statusTableRow = new LinearLayout(this);
statusTableRow.setId(i);
statusTableRow.setOrientation(LinearLayout.VERTICAL);
TextView productsTextView = new TextView(this);
productsTextView.setText("product name:"+i);
statusTableRow.addView(productsTextView);
//statusTableRow.setBackgroundColor(Color.BLACK);
for(int j=0;j<2;j++)
{
RelativeLayout statusRelativelayout = new RelativeLayout(this);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
rl.setMargins(0, 0, 16, 0);
rl.addRule(RelativeLayout.ALIGN_LEFT);
TextView label = new TextView(this);
label.setId(j);
label.setText("abcd:"+j);
label.setLayoutParams(rl);
statusRelativelayout.addView(label);
statusTableRow.addView(statusRelativelayout);
}
statusTableLayout.addView(statusTableRow);}
also put everything inside Relativelayout and then put inside ScrollView like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/statusSecond_Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="#+id/statusDisciplineTable_layout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
</TableLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>

First TableRow is not shown

I'm trying to create a TableLayout, but some error occurs:
The data in the first red colored row are supposed to be in the second, white row.
Here is the layout xml file:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal|vertical"
android:layout_weight="1"
android:background="#838080">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="#+id/myOtherTableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></TableLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000">
<TableLayout
android:id="#+id/myTableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:background="#FFFFFF"
>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
And here is the code:
Color c = new Color();
setContentView(R.layout.data_table_creater_activity);
android.widget.TableRow.LayoutParams params = new TableRow.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(10, 0, 2, 0);
rowFiller();
TableLayout TbL = (TableLayout) findViewById(R.id.myOtherTableLayout);
TableRow headerRowHead = new TableRow(this);
headerRowHead.setId(51);
headerRowHead.setBackgroundColor(c.rgb(241,26,41));
TextView header1 = new TextView(this);
header1.setText(Html.fromHtml("<u>Purchase_Order_Number</u>"));
header1.setLayoutParams(params);
headerRowHead.addView(header1);
TextView header2 = new TextView(this);
header2.setText(Html.fromHtml("<u>Vendor</u>"));
header2.setLayoutParams(params);
headerRowHead.addView(header2);
TextView header3 = new TextView(this);
header3.setText(Html.fromHtml("<u>Currency</u>"));
header3.setLayoutParams(params);
headerRowHead.addView(header3);
TextView header4 = new TextView(this);
header4.setText(Html.fromHtml("<u>Total_Price</u>"));
header4.setLayoutParams(params);
headerRowHead.addView(header4);
TbL.addView(headerRowHead, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
TableRow headerRowData = new TableRow(this);
headerRowData.setId(50);
headerRowData.setBackgroundColor(c.rgb(255,255,255));
TextView headerData1 = new TextView(this);
header1.setText("0350005000");
header1.setLayoutParams(params);
headerRowData.addView(headerData1);
TextView headerData2 = new TextView(this);
header2.setText("Vendor_A");
header2.setLayoutParams(params);
headerRowData.addView(headerData2);
TextView headerData3 = new TextView(this);
header3.setText("EUR");
header3.setLayoutParams(params);
headerRowData.addView(headerData3);
TextView headerData4 = new TextView(this);
header4.setText("44.60");
header4.setLayoutParams(params);
headerRowData.addView(headerData4);
TbL.addView(headerRowData, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
));
Why are the data of the first row not displayed? And why are the data of the second row displayed in the first row?
Working with header1.setText(Html.fromHtml("<u>*Text*</u>"));, to underline text works fine, as you can see in the TableLayout below.
TextView headerData1 = new TextView(this);
header1.setText("0350005000");
header1.setLayoutParams(params);
headerRowData.addView(headerData1);
TextView headerData2 = new TextView(this);
header2.setText("Vendor_A");
header2.setLayoutParams(params);
headerRowData.addView(headerData2);
TextView headerData3 = new TextView(this);
header3.setText("EUR");
header3.setLayoutParams(params);
headerRowData.addView(headerData3);
TextView headerData4 = new TextView(this);
header4.setText("44.60");
header4.setLayoutParams(params);
headerRowData.addView(headerData4);
You have added header3 instead of headerData3 and so on for headerData1 ,headerData2 ,headerData3 .and headerData4 please check that , Is that the issue

Categories