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

  • Home
  • SEARCH
  • 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 7070357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:33:24+00:00 2026-05-28T05:33:24+00:00

I Have activity that get some data from the internet, and shows it to

  • 0

I Have activity that get some data from the internet, and shows it to the screen.
I’m using scroll view cause it’s long text, I also want different text style for a different data,so I use few textViews with a different style and to show it on the Activity screen,
my problem is that scroll view can handle only one view, so how can I use scrolling to show different style of Text view, I tried to add LinearLayout to the scrollView and add all the textViews dynamically in code to this LinearLayout ,but I’m getting exception – scroll view can host only one direct child.

The code below:

/** this is the function, which called from the onClick method.
wanted data object contains 2 strings title message and the message itself.

When debug the code i can see that there's two String values in each loop.
but i cant add the linearLayout to my scrollView - exception ScrollView can host only one direct child */

    private void showResult(ArrayList<WantedData> result) {
        // TODO Auto-generated method stub
        TextView title;
        TextView data;
        scrollLayout = (LinearLayout) findViewById(R.id.LlScrollView);  
        for (WantedData curr : result) {
            if (curr.getTitle() == null) {
                break;
            }

            title = new TextView(this);
            title.setText(curr.getTitle());

            scrollLayout.addView(title, LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT);
            data = new TextView(this);
            data.setText(curr.getData());   
            scrollLayout.addView(data, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        }
        scroll.addView(scrollLayout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

        //at the onCreate method -  scroll = (ScrollView) findViewById(R.id.SvShowTextFromServer);
    }

the xml file:

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

    <include
        android:id="@+id/layout_reffernce"
        layout="@layout/explore" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Enter City" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/EtCity"
                android:layout_width="210dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.14"
                android:orientation="vertical" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/bSearchCity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Search" />
        </LinearLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Enter State" />

        <EditText
            android:id="@+id/EtState"
            android:layout_width="253dp"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </LinearLayout>

    <ScrollView
        android:id="@+id/SvShowTextFromServer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/LlScrollView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/backround"
            android:orientation="vertical" >
        </LinearLayout>


    </ScrollView>

</LinearLayout>
  • 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-28T05:33:25+00:00Added an answer on May 28, 2026 at 5:33 am

    If you have defined a LinearLayout in XML you don’t have to create a new LinearLayout in your code but you have to retrieve the existing one in this way

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LlScrollView);
    

    Otherwise you have to remove the LinearLayout in your XML and add all by code.

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

Sidebar

Related Questions

I have an activity that gets some data from the internet in background while
I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
I have an Activity that retrieves data from a web service. This data is
I have created a custom workflow activity that copies attachments from a case to
In my Android app, I have some data that needs to be synced daily
I have an app that performs some calculations based on data arriving on a
I have a multiple Activity application that progresses the user from entering an IP/Host
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity that launches another activity with startActivityForResult method. I would like

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.