Click here to Skip to main content
15,311,104 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here is my code

XML
TableRow taRow = new TableRow(ctx);
                    // taRow.setLayoutParams(tr.getLayoutParams());
                    TableLayout.LayoutParams tableRowParams=
                            new TableLayout.LayoutParams
                                    (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);

                    int leftMargin=0;
                    int topMargin=30;
                    int rightMargin=0;
                    int bottomMargin=0;

                    tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
                    taRow.setLayoutParams(tableRowParams);
                    taRow.setPadding(0,10,10,10);
                    taRow.setGravity(Gravity.CENTER);
                    taRow.setVisibility(View.VISIBLE);
                    taRow.setBackgroundResource(R.drawable.bg_small_bar);
                    TextView Tv = new TextView(ctx);
                    // Tv.setLayoutParams(((TextView)
                    // (tr).getChildAt(0)).getLayoutParams());
                    Tv.setTextColor(Color.WHITE);
                    Tv.setGravity(Gravity.CENTER);
                    Tv.setText(mStandingLts.get(i).getPosition());
                    taRow.addView(Tv);

                    mTeamL = new LinearLayout(ctx);
                    ImageView mTeamImage = new ImageView(ctx);
                    TextView Tv1 = new TextView(ctx);
                    TableRow.LayoutParams dimParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    dimParams.setMargins(16, 16, 16, 16);
                  //  taRow.setLayoutParams(dimParams);
                    mTeamL.setOrientation(LinearLayout.HORIZONTAL);
                    LinearLayout.LayoutParams viewDimen = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    Tv1.setLayoutParams(viewDimen);
                    LinearLayout.LayoutParams viewDimen1 = new LinearLayout.LayoutParams(64,48);
                    mTeamImage.setLayoutParams(viewDimen1);
                    Picasso.with(ctx).load(mStandingLts.get(i).getTeamLogo()).into(mTeamImage);
                    Tv1.setTextColor(Color.WHITE);
                    Tv1.setGravity(Gravity.CENTER);
                    Tv1.setText(mStandingLts.get(i).getTeam());
                    mTeamL.addView(mTeamImage);
                    mTeamL.addView(Tv1);
                    taRow.addView(mTeamL);

                    /*TextView Tv1 = new TextView(ctx);
                    Tv1.setTextColor(Color.WHITE);
                    Tv1.setGravity(Gravity.CENTER);
                    Tv1.setText(mStandingLts.get(i).getTeam());
                    taRow.addView(Tv1);*/

                    TextView Tv2 = new TextView(ctx);
                    Tv2.setTextColor(Color.WHITE);
                    Tv2.setGravity(Gravity.CENTER);
                    Tv2.setText(mStandingLts.get(i).getPlayed());
                    taRow.addView(Tv2);


                    TextView Tv3 = new TextView(ctx);
                    Tv3.setTextColor(Color.WHITE);
                    Tv3.setGravity(Gravity.CENTER);
                    Tv3.setText(mStandingLts.get(i).getWon());
                    taRow.addView(Tv3);

                    TextView Tv4 = new TextView(ctx);
                    Tv4.setTextColor(Color.WHITE);
                    Tv4.setGravity(Gravity.CENTER);
                    Tv4.setText(mStandingLts.get(i).getLost());
                    taRow.addView(Tv4);


                    TextView Tv7 = new TextView(ctx);
                    Tv7.setTextColor(Color.WHITE);
                    Tv7.setGravity(Gravity.CENTER);
                    Tv7.setText(mStandingLts.get(i).getPoints());
                    taRow.addView(Tv7);
                    tl.addView(taRow);


I have successfully created table layout dynamically ...

the problem is when i cleared the tablelyout and add the data dynamically ..i dono how to add the linear layout content which is having imageview and textview ...

for textview alone i have added

((TextView) (tr).getChildAt(0))
.setText(finalMStandingLts1.get(i).getPosition());
((TextView) (tr).getChildAt(1))
.setText(finalMStandingLts1.get(i).getTeam());
((TextView) (tr).getChildAt(2))
.setText(finalMStandingLts1.get(i).getPlayed());
((TextView) (tr).getChildAt(3))
.setText(finalMStandingLts1.get(i).getWon());
((TextView) (tr).getChildAt(4))
.setText(finalMStandingLts1.get(i).getLost());
((TextView) (tr).getChildAt(5))
.setText(finalMStandingLts1.get(i).getPoints());

and i got the solution right . . .Please guide me how to add this code

XML
mTeamL = new LinearLayout(ctx);
                    ImageView mTeamImage = new ImageView(ctx);
                    TextView Tv1 = new TextView(ctx);
                    TableRow.LayoutParams dimParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    dimParams.setMargins(16, 16, 16, 16);
                  //  taRow.setLayoutParams(dimParams);
                    mTeamL.setOrientation(LinearLayout.HORIZONTAL);
                    LinearLayout.LayoutParams viewDimen = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    Tv1.setLayoutParams(viewDimen);
                    LinearLayout.LayoutParams viewDimen1 = new LinearLayout.LayoutParams(64,48);
                    mTeamImage.setLayoutParams(viewDimen1);
                    Picasso.with(ctx).load(mStandingLts.get(i).getTeamLogo()).into(mTeamImage);
                    Tv1.setTextColor(Color.WHITE);
                    Tv1.setGravity(Gravity.CENTER);
                    Tv1.setText(mStandingLts.get(i).getTeam());
                    mTeamL.addView(mTeamImage);
                    mTeamL.addView(Tv1);
                    taRow.addView(mTeamL);


....
Posted
Updated 8-Jan-16 2:58am
v2
Comments
Yuriy Loginov 8-Jan-16 17:55pm
   
Did you add your TableRow to the TableLayout? So something like this tableLayout.addView(taRow);
CrimeKumar66 9-Jan-16 0:48am
   
ya i have added..i got result for my first set of code. .. .my doubt is how to add this to dynamicallyy like i have added the text view like this . .

((TextView) (tr).getChildAt(5))
.setText(finalMStandingLts1.get(i).getPoints());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900