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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:58:24+00:00 2026-05-23T07:58:24+00:00

i have a complex xml layout which has list views..a row in the list

  • 0

i have a complex xml layout which has list views..a row in the list view contains several text fields which are spaced evenly. i am using textview to store the text and then finally add all the items to the row…its working perfectly fine.
but now i have case where in i am not sure, how many text fields i might get from a webservice. therefore i need to create the textview dynamically on run time, populate them and then insert into the list..
is there anyway to declare,add and populate new textview fields on runtime?
or is there is anyway to implement the spacing between the two fields?

result of first call

__________________________
|_____|_____|_____|______| 

result of second call

________________________________
|_____|_____|_____|______|______|

I tried implementing the solution that was provided below (Kenny), but for some reason I am unable to add views into the list.. below is my code

public class HeaderAdapter extends ArrayAdapter<Header> {
final Header[] listSymbols;
private TextView textView;
private LinearLayout row;

public HeaderAdapter(Context context, int symResourceID,
        Header[] objects) {
    super(context, symResourceID, objects);
    listSymbols = objects;

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext()
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View row = inflater.inflate(R.layout.header_view, parent, false);
    Header headerRec = listSymbols[position];
    for(int i = 0 ; i < listSymbols.length;i++){
        textView = new TextView(getContext());
        textView.setLayoutParams(new LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,  //Width of the view
                ViewGroup.LayoutParams.WRAP_CONTENT));//Height of the view
        textView.setId(i);
            row.add??

        }
}

The main activity that calls this

setContentView(R.layout.main);

    headerList.add(new Header("Symbol","Quantity","Price","Price Yesterday","52 Week High","52 Week Low","Change","Days Gain","Days Gain %","Returns"));

            Header[] tmpHeaderList = headerList.toArray(new Header[headerList.size()]);

            ArrayAdapter<Header> headerAdapter = new HeaderAdapter(this,R.layout.twoway_header_view,tmpHeaderList);
            headerListView.setAdapter(headerAdapter);

xml layout file..the main file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">

    <HorizontalScrollView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:scrollbars="none"
        android:id="@+id/headerHv">

        <ListView android:id="@+id/header_listView1"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:background="@color/white" android:cacheColorHint="#00000000"
            android:smoothScrollbar="true" android:scrollbars="none" />
    </HorizontalScrollView>
</LinearLayout>

the file in which the template for the row is defined

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <TextView android:id="@+id/headerList" android:layout_width="80dp"
        android:layout_height="wrap_content" android:textColor="#000000"
        android:typeface="sans" android:textStyle="normal"  />

</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-23T07:58:24+00:00Added an answer on May 23, 2026 at 7:58 am

    Here is the way i dynamically generate custom buttons from a list, you could do the same thing with textViews:

    //Setup Buttons
        layout = (LinearLayout)findViewById(R.id.layoutBars);
        int count = lBars.size();
        for(int i = 0; i< count;i++){
            final Bar b = lBars.get(i);
            BarButton button = new BarButton(DDTBars.this, R.drawable.barsmall , b.getName().toUpperCase());
            button.setLayoutParams(new LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
            button.setId(i);
            button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    //Run activity passing name of the bar to retrieve data
                    Intent i = new Intent(DDTBars.this, DDTBar.class);
                    i.putExtra("name", b.getName());
                    startActivity(i);
                }
            });
            layout.addView(button);         
        }
    

    So you could try:

        //Setup TextViews
        layout = (LinearLayout)findViewById(R.id.mylayout);
        int count = myTextList.size();
        for(int i = 0; i< count;i++){
            TextView txtView = new TextView(this);
            txtView.setLayoutParams(new LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,  //Width of the view
                    ViewGroup.LayoutParams.WRAP_CONTENT));//Height of the view
            txtView.setId(i);
            layout.addView(txtView);            
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex empty view in a layout, with an icon, text, button,
I have a reasonably complex XML document which I want to flatten down to
I have a LinearLayout view that already contains several elements. I want to add
I have a number rather large, complex xml documents that I need to loop
I have a 'complex item' that is in XML, Then a 'workitem' (in xml)
I have a complex XSD schema and hundreds of XML files conforming to the
I have an xml with an xml-schema. The xml-schema defines an abstract complex type
I am using WCF and REST, and I have complex types, which are working
i have complex xslt that formats xml to html now i need to be
I have a dataset that I read in from a complex xml structure.... here

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.