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 7007637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:37:58+00:00 2026-05-27T21:37:58+00:00

I’ve been banging my head on this one for a couple days. I’ve done

  • 0

I’ve been banging my head on this one for a couple days. I’ve done a ton of research and tried a whole bunch of different approaches, but I just can’t seem to get this to work.

What I’m trying to do is setup a dynamic layout in a for loop while processing multiple rows in a JSON response.

There are five database fields that get returned, including the path to an image on my web server.

The problem isn’t assigning and displaying the data and image, the problem is displaying it all in the right position.

My code is reverted to a hideously basic table layout and multiple rows.

Here’s what it’s doing right now….(apologies for not being able to post an image, but evidently I need some stack points to do that – each line represents a table row).

|   image   |
|    data    |
|    data    |
| data data|

and here is the code (that I know is not what I need) to set this up…

                   for (int i = 0; i < array.length(); i++) {
                try {
                   //all my json work is here
                   TableLayout tl = (TableLayout)findViewById(R.id.bottlelisttablelayout);
                          //create image table row for now
                  TableRow imagetr = new TableRow(this);
                  imagetr.setLayoutParams(new LayoutParams(
                                  LayoutParams.WRAP_CONTENT,
                                  LayoutParams.WRAP_CONTENT));
                   final ImageView bottleiv = new ImageView(this);
                   bottleiv.setId(bottleID);
                   bottleiv.setLayoutParams(new LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                   bottleiv.getLayoutParams().height=75;
                   bottleiv.getLayoutParams().width=75;
                   bottleiv.setAdjustViewBounds(true);
                   bottleiv.setScaleType(ScaleType.CENTER_INSIDE);
                   String imageURL = bottlePicture;
                   Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
                   bottleiv.setImageBitmap(bitmap);
                   bottleiv.setVisibility(View.VISIBLE);
                   imagetr.addView(bottleiv);
                   imagetr.setClickable(true);

                   /* Create a new row to be added. */
                   TableRow tr = new TableRow(this);
                   tr.setLayoutParams(new LayoutParams(
                                  LayoutParams.FILL_PARENT,
                                  LayoutParams.WRAP_CONTENT));

                   final TextView bottleTextView = new TextView(this);
                   bottleTextView.setId(bottleID);
                   bottleTextView.setText(Html.fromHtml(data_field1));
                   bottleTextView.setLayoutParams(new LayoutParams(
                           LayoutParams.FILL_PARENT,
                           LayoutParams.WRAP_CONTENT,
                           1.0f));
                   bottleTextView.setTextColor(Color.BLACK);
                   bottleTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                   bottleTextView.setTextSize(12);
                   tr.setPadding(0, 0, 0, 0);  //left, top, right, bottom
                   tr.addView(bottleTextView);
                   tr.setClickable(true);

                   TableRow tr2 = new TableRow(this);
                   tr2.setLayoutParams(new LayoutParams(
                                  LayoutParams.FILL_PARENT,
                                  LayoutParams.WRAP_CONTENT));
                   final TextView bottleTextView2 = new TextView(this);
                   bottleTextView2.setId(bottleID);
                   bottleTextView2.setText(Html.fromHtml("some text"+datafield2));
                   bottleTextView2.setLayoutParams(new LayoutParams(
                           LayoutParams.FILL_PARENT,
                           LayoutParams.WRAP_CONTENT,
                           1.0f));
                   bottleTextView2.setTextColor(Color.GRAY);
                   bottleTextView2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                   bottleTextView2.setTextSize(8);
                   tr2.setPadding(0, 0, 0, 0);  //left, top, right, bottom
                   tr2.addView(bottleTextView2);
                   tr2.setClickable(true);

                   TableRow tr3 = new TableRow(this);
                   tr2.setLayoutParams(new LayoutParams(
                                  LayoutParams.FILL_PARENT,
                                  LayoutParams.WRAP_CONTENT));
                   final TextView bottleTextView3 = new TextView(this);
                   bottleTextView3.setId(bottleID);
                   bottleTextView3.setText(Html.fromHtml("some text: "+datafield3));
                   bottleTextView3.setLayoutParams(new LayoutParams(
                           LayoutParams.FILL_PARENT,
                           LayoutParams.WRAP_CONTENT,
                           1.0f));
                   bottleTextView3.setTextColor(Color.GRAY);
                   bottleTextView3.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                   bottleTextView3.setTextSize(8);
                   tr3.setPadding(0, 0, 0, 0);  //left, top, right, bottom
                   tr3.addView(bottleTextView3);
                   tr3.setClickable(true);

                   TableRow tr4 = new TableRow(this);
                   tr2.setLayoutParams(new LayoutParams(
                                  LayoutParams.FILL_PARENT,
                                  LayoutParams.WRAP_CONTENT));
                   final TextView bottleTextView4 = new TextView(this);
                   bottleTextView4.setId(bottleID);
                   bottleTextView4.setText(Html.fromHtml("some text"+datafield4));
                   bottleTextView4.setLayoutParams(new LayoutParams(
                           LayoutParams.FILL_PARENT,
                           LayoutParams.WRAP_CONTENT,
                           1.0f));
                   bottleTextView4.setTextColor(Color.BLACK);
                   bottleTextView4.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                   bottleTextView4.setTextSize(12);
                   final TextView bottleTextView5 = new TextView(this);
                   bottleTextView5.setId(bottleID);
                   bottleTextView5.setText(Html.fromHtml("some text"+datafield5));
                   bottleTextView5.setLayoutParams(new LayoutParams(
                           LayoutParams.FILL_PARENT,
                           LayoutParams.WRAP_CONTENT,
                           1.0f));
                   bottleTextView5.setTextColor(Color.BLACK);
                   bottleTextView5.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                   bottleTextView5.setTextSize(12);
                   tr4.setPadding(0, 0, 0, 0);  //left, top, right, bottom
                   tr4.addView(bottleTextView4);
                   tr4.addView(bottleTextView5);
                   tr4.setClickable(true);

                   imagetr.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            Intent intent = new Intent(getApplicationContext(), SingleBottleDisplay.class);
                            //Toast.makeText(GuruBottles.this,"bottleID = "+headerTextView.getId(), Toast.LENGTH_SHORT).show();
                            intent.putExtra("id", bottleTextView.getId());
                            startActivityForResult(intent,0);
                        }
                    });
                   tr.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            Intent intent = new Intent(getApplicationContext(), SingleBottleDisplay.class);
                            //Toast.makeText(GuruBottles.this,"bottleID = "+headerTextView.getId(), Toast.LENGTH_SHORT).show();
                            intent.putExtra("id", bottleTextView.getId());
                            startActivityForResult(intent,0);
                        }
                    });
                       tr2.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                Intent intent = new Intent(getApplicationContext(), SingleBottleDisplay.class);
                                //Toast.makeText(GuruBottles.this,"bottleID = "+headerTextView.getId(), Toast.LENGTH_SHORT).show();
                                intent.putExtra("id", bottleTextView.getId());
                                startActivityForResult(intent,0);
                            }
                        });
                       tr3.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                Intent intent = new Intent(getApplicationContext(), SingleBottleDisplay.class);
                                //Toast.makeText(GuruBottles.this,"bottleID = "+headerTextView.getId(), Toast.LENGTH_SHORT).show();
                                intent.putExtra("id", bottleTextView.getId());
                                startActivityForResult(intent,0);
                            }
                        });
                       tr4.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                Intent intent = new Intent(getApplicationContext(), SingleBottleDisplay.class);
                                //Toast.makeText(GuruBottles.this,"bottleID = "+headerTextView.getId(), Toast.LENGTH_SHORT).show();
                                intent.putExtra("id", bottleTextView.getId());
                                startActivityForResult(intent,0);
                            }
                        });

                      /* Add row to TableLayout. */
                       tl.addView(imagetr,new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                       tl.addView(tr,new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                       tl.addView(tr2,new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                       tl.addView(tr3,new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                       tl.addView(tr4,new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
} catch (JSONException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

This is my xml code…

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottlelistlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="@drawable/background"
    android:layout_gravity="center">
    <TextView
        android:id="@+id/guruTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/guru"
        android:textStyle="bold"
        android:textSize="15dp"
        android:textColor="#FFFFFF"
        android:shadowColor="#000000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="1.5"
        android:gravity="center" />
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/guruTitle"
        android:layout_above="@id/radiogroup"
        android:scrollbarStyle="outsideInset"
        android:background="#ffffff" >
         <TableLayout
            android:id="@+id/bottlelisttablelayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="75dp"
            android:layout_gravity="right"
            android:layout_marginBottom="35dp"
            android:shrinkColumns="0" >
         </TableLayout>
     </ScrollView>
    <include layout="@layout/actnavbar" />
</RelativeLayout>

Here is what I really need…where the image is to the left of all four data rows.

|         |   data
|         |   data
|image|   data
|         |data  data

Could someone please point me in the right direction?

Many thanks in advance for any help I can get.

  • 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-05-27T21:37:59+00:00Added an answer on May 27, 2026 at 9:37 pm

    You can define the individual item you want to show in a separate xml file (which will help you design the view), and then dynamically load the xml to your TableLayout or a ListView (I prefer the latter).

    Have you thought of using an adapter (like a BaseAdapter) to do this?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.