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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:17:26+00:00 2026-06-10T18:17:26+00:00

I’m working on project and main layout contains ListView. I want to dynamically add

  • 0

I’m working on project and main layout contains ListView. I want to dynamically add subItems to ListViewItem View. My main layout is as follows :

main_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="TextView"/>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >
    </ListView>
</RelativeLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:background="@android:color/transparent" >

</LinearLayout>

And I want to add TextView to returned view in getView with following properties :

  1. Height : fill_parent
  2. Width : wrap_content
  3. Text : Text View Item

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) this.M_context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item, parent, false);
    
        return convertView;
    }
    

Please note that, I want to dynamically add subItems to ListViewItem. You can suppose that, I have array of TextView and want to fill my listView using this Items. How can I do this scenario ? I can not find any result with searching on other threads and aslo Google. So, Could any one please help me to solve my problem ?

Thanks in Advance 🙂

  • 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-10T18:17:28+00:00Added an answer on June 10, 2026 at 6:17 pm

    This was my getView() method.

    main.xml

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_below="@+id/button1"
        android:cacheColorHint="@android:color/transparent"
        android:divider="#00ff00"
        android:fastScrollEnabled="true"
        android:focusable="false"
        android:listSelector="#000000"
        android:paddingTop="5dp"
        android:saveEnabled="true" >
    </ListView>
    

    item.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </LinearLayout>
    

    Adapter

     class CustomAdapter extends ArrayAdapter<String> {
    
        public CustomAdapter(Context context, int resource, List<String> objects) {
            super(context, resource, objects);
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            ViewHolder holder = null;
    
            /*convertView = mInflater.inflate(R.layout.item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
            holder = (ViewHolder) convertView.getTag();
    
            holder.getAppName().setText(str.get(position));*/
    
            if(position==0)
            {
                ImageView iv = new ImageView(getApplicationContext());
                iv.setBackgroundResource(R.drawable.ic_launcher);
                convertView = iv;
            }
            else if(position==1)
            {
                TextView tv = new TextView(getApplicationContext());
                tv.setText("text view");
                convertView = tv;
            }
            else
            {
                EditText et = new EditText(getApplicationContext());
                et.setText("ET go home");
                convertView = et;
            }
    
            return convertView;
        }
    
        private class ViewHolder {
            private View pathRow;
            private TextView appNameView = null;
    
            public ViewHolder(View row) {
                pathRow = row;
            }
    
            public TextView getAppName() {
                if (null == appNameView) {
                    appNameView = (TextView) pathRow.findViewById(R.id.tv);
                }
                return appNameView;
            }
        }
    }
    

    The commented out portion is the one used to be. The code below it is the one which I used to dynamically generate the view and return them. my listitem.xml still has a textView in it. But the adapter sets the view which we are returning from getView(). This works for me.

    I really don;t see the point of the LinearLayout in your item.xml. You can do that in your own code.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.