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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:25:14+00:00 2026-06-03T06:25:14+00:00

i am trying to create tablelayout inside scrollview but it gives me erorr i

  • 0

i am trying to create tablelayout inside scrollview but it gives me erorr
i have multiple tablelayout on screen whichi is fill dynamically using imageview
here i put my logcat error

Logcat error

05-07 15:36:33.193: E/AndroidRuntime(681): java.lang.ClassCastException: android.widget.TableLayout$LayoutParams

main.xml

   <?xml version="1.0" encoding="utf-8"?>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
       <ScrollView 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
        >
     <TableLayout  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:id="@+id/itable">
        <TableRow
                 android:id="@+id/trstate"
                 android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
         >
        <TextView
        android:id="@+id/tstate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NewYork"
        android:textAppearance="?android:attr/textAppearanceLarge" />
          </TableRow>
        <TableRow
                 android:id="@+id/trimage"
                 android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                >
        <ImageView  
                 android:id="@+id/iimage"
         android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                         />

        </TableRow>

    </TableLayout>

       </ScrollView>

</LinearLayout>

TableActivity.java

    package com.table.image;

     import java.io.BufferedInputStream;
     import java.io.InputStream;
     import java.net.URL;
     import java.net.URLConnection;
     import android.app.Activity;
     import android.content.Context;
     import android.graphics.Bitmap;
     import android.graphics.BitmapFactory;
       import android.os.Bundle;
    import android.util.Log;
    import android.view.Gravity;
     import android.widget.ImageView;
     import android.view.ViewGroup;
    import android.widget.TableLayout;
   import android.widget.TableLayout.LayoutParams;
   import android.widget.TableRow;
import android.widget.TextView;

public class TableLayoutActivity extends Activity {
    /** Called when the activity is first created. */

    public TableLayout itable;
    public TableRow trimage;
    public TableRow trstate;
    public ImageView iimage;
    public TextView tstate;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        itable = (TableLayout)findViewById(R.id.itable);
        itable.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));

        for (int i = 0; i < 3; i++) {

            trstate = new TableRow(this);
            trstate.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));

            tstate = new TextView(this);
            tstate.setLayoutParams(new TableRow.LayoutParams(50,50));
            tstate.setText("NewYork");
            trstate.addView(tstate);



            trimage = new TableRow(this);
            trimage.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
            for (int j = 0; j < 3; j++)
            {   
                Log.i("Test",Integer.toString(i) + "-" + Integer.toString(j));
                iimage = new ImageView(this);
                iimage.setPadding(8,8,8,8);
                iimage.setLayoutParams(new TableRow.LayoutParams(100,100));
                iimage.setImageResource(R.drawable.abc);
                trimage.addView(iimage);
             }            
            itable.addView(trimage);
            itable.addView(trstate);

        }

    }
}
  • 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-03T06:25:15+00:00Added an answer on June 3, 2026 at 6:25 am

    You are creating TableLayout inside LinearLayout which is not correct. Make ScrollView as root layout.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:gravity="center">
    
    <AutoCompleteTextView
    android:id="@+id/autoCompleteTextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:ems="10"
    android:text="AutoCompleteTextView" >
    
    <requestFocus />
    
    </AutoCompleteTextView>
    
    </LinearLayout>
    
    <ScrollView 
    android:id="@+id/scrollview1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical" android:layout_marginTop="10dip">
    
    <TableLayout  android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:id="@+id/itable">
    <TableRow
             android:id="@+id/trstate"
             android:layout_height="wrap_content"
              android:layout_width="wrap_content">
    
     </TableRow>
     <TableRow
             android:id="@+id/trimage"
             android:layout_height="wrap_content"
              android:layout_width="wrap_content"
            >
    <ImageView  
             android:id="@+id/iimage"
     android:layout_width="wrap_content"
        android:layout_height="wrap_content"
                     />
    
    <TextView
        android:id="@+id/tstate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NewYork"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </TableRow>
    
    </TableLayout>
    
    </ScrollView>
    
    </LinearLayout>
    

    Edit:

     public class SampleAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    
    public TableLayout itable;
    public TableRow trimage;
    public TableRow trstate;
    public ImageView iimage;
    public TextView tstate;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        itable = (TableLayout) findViewById(R.id.itable);
        /*Remove this line 
         * itable.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
         * LayoutParams.WRAP_CONTENT));
         */
    
        for (int i = 0; i < 3; i++) {
    
            trstate = new TableRow(this);
            trstate.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
    
            tstate = new TextView(this);
            tstate.setLayoutParams(new LayoutParams(50, 50));
            tstate.setText("NewYork");
            trstate.addView(tstate);
    
            trimage = new TableRow(this);
            trimage.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
            for (int j = 0; j < 3; j++) {
                Log.i("Test", Integer.toString(i) + "-" + Integer.toString(j));
                iimage = new ImageView(this);
                iimage.setPadding(8, 8, 8, 8);
                iimage.setLayoutParams(new LayoutParams(100, 100));
                iimage.setImageResource(R.drawable.events);
                trimage.addView(iimage);
            }
            itable.addView(trimage);
            itable.addView(trstate);
    
        }
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a basic datasheet in my application using a TableLayout.
I'm trying to create an android screen that has a TableLayout anchored to the
I'm trying to create a TableLayout dynamically which has all its rows stretched like
I'm trying to create a View dynamically (on click). Any person have any idea
I m trying to create a tableLayout. My problem is that my table content
I'm trying create a template with django but when I execute this sentences in
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a user account in a test. But getting a Object reference
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different

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.