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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:09:14+00:00 2026-06-15T20:09:14+00:00

I’am trying to make a ListView that contains two items (two textView’s) Here is

  • 0

I’am trying to make a ListView that contains two items (two textView’s)

Here is my code:

Header XML:

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

     <TextView android:id="@+id/txtHeader"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:textStyle="bold"
        android:textSize="22dp"
        android:textColor="#FFFFFF"
        android:padding="10dp"
        android:text="Shoping List"
        android:background="#336699" />

</LinearLayout>

Hers is the row XML:

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

     <TextView android:id="@+id/prudctName"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textStyle="bold"
        android:textSize="22sp"
        android:textColor="#000000"
     />

     <TextView android:id="@+id/productAmount"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textStyle="bold"
        android:textSize="22sp"
        android:textColor="#000000"
         />

</LinearLayout>

Here is the MAIN SCREEN XML:

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

     <ListView
        android:id="@+id/shoping_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

Here is the class that represents the object containing the two filed:

public class ShopingListItem
{
    public String productName;
    public String procuctAmount;
    public ShopingListItem(String _productName,String _productAmount)
    {
        this.procuctAmount=_productAmount;
        this.productName=_productName;
    }

}

Here is the Adapter class:

    public class ShopingListItemAdapter extends ArrayAdapter<ShopingListItem>
    {

        public Context context;
        public int layoutResourceId;
        public ShopingListItem[] items;

        public ShopingListItemAdapter(Context context,int layoutResourceId, ShopingListItem[] objects)
        {
            super(context, layoutResourceId, objects);
            this.context=context;
            this.layoutResourceId=layoutResourceId;
            this.items=objects;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View row = convertView;
            ShopingListItemHolder holder = null;

            if(row==null)
            {
                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);
                holder = new ShopingListItemHolder();
                holder.productName=(TextView)row.findViewById(R.id.prudctName);
                holder.productAmount=(TextView)row.findViewById(R.id.productAmount);
                row.setTag(holder); 
            }
            else
            {
                 holder = (ShopingListItemHolder)row.getTag();
            }

             ShopingListItem item = items[position];
             String amount = item.procuctAmount;
             String name = item.productName;
             TextView v = holder.productAmount;
             TextView vv = holder.productName;
             holder.productAmount.setText(amount);
             holder.productName.setText(name);

            return row;
        }
         static class ShopingListItemHolder
            {
                TextView productName;
                TextView productAmount;
            }


    }

Here is the main activity:

public class ShopingListActivity extends Activity
{
    private ListView listView1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.shoping_list_screen);

        //fill list with temp data
        ShopingListItem[] items = fillData();
        ShopingListItemAdapter adapter = new ShopingListItemAdapter(this, R.layout.listview_item_row, items);

        listView1 = (ListView)findViewById(R.id.shoping_list);

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        listView1.addHeaderView(header);
        listView1.setAdapter(adapter);

    }

    private ShopingListItem[] fillData()
    {
         ShopingListItem[] items = new ShopingListItem[]
                    {
                       new ShopingListItem("Bamba", "2"),
                       new ShopingListItem("Bisli", "12"),
                       new ShopingListItem("Shoko", "3"),
                       new ShopingListItem("Yello Cheese", "2"),
                       new ShopingListItem("Marak", "7"),
                       new ShopingListItem("Cola", "2"),
                       new ShopingListItem("Orez", "3"),
                       new ShopingListItem("Kaki", "9"),
                       new ShopingListItem("Battery", "1"),
                       new ShopingListItem("Bla", "1"),
                       new ShopingListItem("Bla bla", "100"),
                       new ShopingListItem("bbb", "200"),
                       new ShopingListItem("Red", "2"),


                     };
         return items;
    }
}

The result of the code is a list but with only one item (the name) the amount isnt add’d

Can anyone find the problem?

  • 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-15T20:09:15+00:00Added an answer on June 15, 2026 at 8:09 pm

    Your row layout’s first TextView fills the entire row, pushing the second TextView off of the screen. You need to change your row layout. Either use wrap_content:

    <TextView android:id="@+id/prudctName"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        ... />
    

    Or you can incorporate layout_weight.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.