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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:52:03+00:00 2026-06-08T04:52:03+00:00

I have populated a listview(4columns) using simpleadapter and hashmap. Now I would like to

  • 0

I have populated a listview(4columns) using simpleadapter and hashmap. Now I would like to have each column of the listview a name.

My listview is displayed inside a linear layout with 4 textviews.

Now, in order to have attribute name of each column, I try to have 2 linear layouts, and the top linear layout have 4 textviews with the attribute names, the bottom linear layout with the data from simpleadapter. And put two linear layouts inside a another linear layout.

And this didn’t work the way i want…
I am fairly new to android, please help.

Edit:

Here is my code:

public class MultiList extends ListActivity {

ListView lv;
SimpleAdapter sd;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Calendar c = Calendar.getInstance();
    lv = getListView();
    ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String,String>>();
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("Date", ""+c.get(Calendar.DATE));
    map.put("Month", ""+c.get(Calendar.MONTH)+1);
    map.put("Time", "" + new Date().toString());
    aList.add(map);
    map = new HashMap<String, String>();
    map.put("Date", ""+c.get(Calendar.DATE));
    map.put("Month", ""+c.get(Calendar.MONTH)+1);
    map.put("Time", "" + new Date().toString());
    aList.add(map);
    map = new HashMap<String, String>();
    map.put("Date", ""+c.get(Calendar.DATE));
    map.put("Month", ""+c.get(Calendar.MONTH)+1);
    map.put("Time", "" + new Date().toString());
    aList.add(map);
    sd= new SimpleAdapter(this, aList, R.layout.main, new String[]{"Date","Month","Time"}, new int[]{R.id.studentID,R.id.studentAge,R.id.studentName});
    lv.setAdapter(sd);



   // insertData();


}

My main.xml

<?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" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:paddingBottom="6dip"
        android:paddingTop="4dip" >

        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student ID" />

        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student Age" />

        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student Name" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:paddingBottom="6dip"
        android:paddingTop="4dip" >

        <TextView
            android:id="@+id/studentID"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
             />

        <TextView
            android:id="@+id/studentAge"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
           />

        <TextView
            android:id="@+id/studentName"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
             />
    </LinearLayout>

</LinearLayout>

The problem is, each of the attribute name (student ID, student Age, Student Name) is repeated on every row. How do I fix that?

  • 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-08T04:52:05+00:00Added an answer on June 8, 2026 at 4:52 am

    Break your layout into two, the first one will have the column headers. Let’s call it header.xml:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:paddingBottom="6dip"
        android:paddingTop="4dip" >
    
        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student ID" />
    
        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student Age" />
    
        <TextView
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="student Name" />
    </LinearLayout>
    

    The second one is simply for each row, called row.xml

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:paddingBottom="6dip"
        android:paddingTop="4dip" >
    
        <TextView
            android:id="@+id/studentID"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
             />
    
        <TextView
            android:id="@+id/studentAge"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
           />
    
        <TextView
            android:id="@+id/studentName"
            android:layout_width="90dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
             />
    </LinearLayout>
    

    (You can give them better names later.)

    Now your onCreate() should have this:

    // Set up your header
    lv.addHeaderView(getLayoutInflater().inflate(R.layout.header, null, false));
    
    // Change the resource id to R.layout.row
    sd = new SimpleAdapter(this, aList, R.layout.row, new String[]{"Date","Month","Time"}, new int[]{R.id.studentID,R.id.studentAge,R.id.studentName});
    lv.setAdapter(sd);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView which is populated using a CursorAdapter. I'd also like to
I have created a custom listview that is populated using a row.xml file. Each
I have a listview populated like this: lv1 = (ListView) findViewById(R.id.ListView01); ArrayList<HashMap<String, String>> mylist
I have a ListView that is populated using an XML file. However, I want
I have a ListView that's populated from a SimpleCursorAdapter each row containing 3 different
I have 3 ListView's that are populated like this (well this can be anything,
I have a ListView in a ListActivity populated by a database table. Each row
I have a ListView which is populated by a SQLite query in OnCreate using
I have a ListView that is being populated with a custom adapter. I'd like
I have a ListView populated by a SimpleAdapter, which gets values from an ArrayList

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.