Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:36:14+00:00 2026-06-08T20:36:14+00:00

I am trying to add table rows to a table using layout inflator. Here

  • 0

I am trying to add table rows to a table using layout inflator.

Here is my XML file,called customlistviewitem.xml

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:id="@+id/LinearLayout01"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <ScrollView
   android:id="@+id/ScrollView1"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginTop="75dp">
  <TableLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:id="@+id/myTableLayout1">

<TableRow android:layout_marginTop="1dp" android:layout_marginLeft="10dp">

    </TableRow>
    </TableLayout>

    </ScrollView>
    </LinearLayout>

Here is the code I am using to add rows to the table

    LinearLayout l = (LinearLayout) findViewById(R.id.mylayout1);
            LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            JSONArray jArray;
            try {
                jArray = new JSONArray(result);

            JSONObject json_data=null;
            for(int i=0;i<jArray.length();i++){
                //Log.e("Carlist","Result" +result);
                json_data = jArray.getJSONObject(i);
                   int ct_id = json_data.getInt("id");
                   String make = json_data.getString("make");
                   String model = json_data.getString("model");
                   String price = json_data.getString("price");

                   TableRow tr = new TableRow(this);
                         tr.setId(ct_id);
                         tr.setClickable(true);

                         tr.setOnClickListener(new  OnClickListener() {

                                @Override
                                public void onClick(final View v) {

                                    String sdet_id;
                                    int det_id;
                        //          v.setBackgroundColor(Color.GRAY);
                                    det_id = v.getId();
                                    sdet_id = String.valueOf(det_id);
                                    final Intent i = new Intent();
                                    i.setClassName("demo.example.com", "demo.example.com.cardetails");
                                    i.putExtra("Det_id", sdet_id);
                                    startActivity(i);

                          //        v.setBackgroundColor(Color.TRANSPARENT);
                                    // TODO Auto-generated method stub
                                }
                            });
                         TableLayout.LayoutParams tableRowParams=
                              new TableLayout.LayoutParams
                              (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);

                            int leftMargin=20;
                            int topMargin=10;
                            int rightMargin=15;
                            int bottomMargin=20;

                            tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

                            tr.setLayoutParams(tableRowParams);

                              /* Create a Button to be the row-content. */
                         ImageView myimage = new ImageView(this);

                         BitmapFactory.Options bmOptions;
                        bmOptions = new BitmapFactory.Options();
                        bmOptions.inSampleSize = 1;
                        Bitmap bm = LoadImage(image_URL, bmOptions);
                        myimage.setImageBitmap(bm);
                         tr.addView(myimage);
                         TextView tmake=new TextView(this);
                        // tmake.setText(make);
                         tmake.setText(Html.fromHtml("<H1>" + make));
                         tr.addView(tmake); 

                         TextView tmodel=new TextView(this);
                         tmodel.setText(Html.fromHtml("<b><H1>" + "&nbsp;&nbsp;" + "€" + price + "</b></H1></br></br>" ));
                         tr.addView(tmodel);



                    /* Add row to TableLayout. */
                     //  tr.setPadding(50, 0, 0, 0);
                         tl.addView(tr);
                         View v = new View(this);
                         v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
                         v.setBackgroundColor(Color.rgb(51, 51, 51));
                         tl.addView(v);

            }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

This is not adding the table row. What do I need to do to add the row and the text items?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:36:16+00:00Added an answer on June 8, 2026 at 8:36 pm

    Issue seems with LayoutParams set to The TableRow, and Views being added to TableRow, try Commenting the setting layout param code and then check the result.

    LinearLayout l = (LinearLayout) findViewById(R.id.mylayout1);
                LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                JSONArray jArray;
                try {
                    jArray = new JSONArray(result);
    
                JSONObject json_data=null;
                for(int i=0;i<jArray.length();i++){
                    //Log.e("Carlist","Result" +result);
                    json_data = jArray.getJSONObject(i);
                       int ct_id = json_data.getInt("id");
                       String make = json_data.getString("make");
                       String model = json_data.getString("model");
                       String price = json_data.getString("price");
    
                       TableRow tr = new TableRow(this);
                             tr.setId(ct_id);
                             tr.setClickable(true);
    
                             tr.setOnClickListener(new  OnClickListener() {
    
                                    @Override
                                    public void onClick(final View v) {
    
                                        String sdet_id;
                                        int det_id;
                            //          v.setBackgroundColor(Color.GRAY);
                                        det_id = v.getId();
                                        sdet_id = String.valueOf(det_id);
                                        final Intent i = new Intent();
                                        i.setClassName("demo.example.com", "demo.example.com.cardetails");
                                        i.putExtra("Det_id", sdet_id);
                                        startActivity(i);
    
                              //        v.setBackgroundColor(Color.TRANSPARENT);
                                        // TODO Auto-generated method stub
                                    }
                                });
    
    
                                  /* Create a Button to be the row-content. */
                             ImageView myimage = new ImageView(this);
    
                             BitmapFactory.Options bmOptions;
                            bmOptions = new BitmapFactory.Options();
                            bmOptions.inSampleSize = 1;
                            Bitmap bm = LoadImage(image_URL, bmOptions);
                            myimage.setImageBitmap(bm);
                             tr.addView(myimage);
                             TextView tmake=new TextView(this);
                            // tmake.setText(make);
                             tmake.setText(Html.fromHtml("<H1>" + make));
                             tr.addView(tmake); 
    
                             TextView tmodel=new TextView(this);
                             tmodel.setText(Html.fromHtml("<b><H1>" + "&nbsp;&nbsp;" + "€" + price + "</b></H1></br></br>" ));
                             tr.addView(tmodel);
    
    
    
                        /* Add row to TableLayout. */
                         //  tr.setPadding(50, 0, 0, 0);
                             tl.addView(tr);
                             View v = new View(this);
    
                             v.setBackgroundColor(Color.rgb(51, 51, 51));
                             tl.addView(v);
    
                }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here in the below fiddle, i am trying to add and remove table rows
I'm trying to add and remove some rows from a table using Jquery. But
I'm trying to add details to a database by using ajax and table dynamic
I have created a Table Layout named table and I am trying to add
I'm trying to randomly grab about 20 random rows from a table, then using
I am trying to add rows to my repeater using jQuery using below script.It
I am trying to add a bunch of rows to an empty Table during
I am trying to add a row to a table in the database using
I'm trying to insert rows using raw sql in django: The input file has
I am trying to implement a slide down for table rows using the previous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.