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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:38+00:00 2026-06-15T12:19:38+00:00

I would like to create a listview with custom rows. I have created a

  • 0

I would like to create a listview with custom rows. I have created a class that extends ListActivity and an XML for each row item. I’ve also added a method that generates some dummy data. But this is where I’m stuck. How do I call this from my main class and populate a listview in my main.xml?

CustomListView.java

public class CustomListView extends ListActivity  {

private ArrayList<HashMap<String,String>> list;

public CustomListView(){

    list =  new ArrayList<HashMap<String,String>>();

    SimpleAdapter adapter = new SimpleAdapter(
            this,
            list,
            R.layout.custom_list_item,
            new String[] {"pen","price","color"},
            new int[] {R.id.text1,R.id.text2, R.id.text3});

    populateList();

    setListAdapter(adapter);

}

private void populateList() {

    HashMap<String,String> temp = new HashMap<String,String>();
    temp.put("pen","MONT Blanc");
    temp.put("price", "200.00$");
    temp.put("color", "Silver, Grey, Black");
    list.add(temp);
    HashMap<String,String> temp1 = new HashMap<String,String>();
    temp1.put("pen","Gucci");
    temp1.put("price", "300.00$");
    temp1.put("color", "Gold, Red");
    list.add(temp1);
    HashMap<String,String> temp2 = new HashMap<String,String>();
    temp2.put("pen","Parker");
    temp2.put("price", "400.00$");
    temp2.put("color", "Gold, Blue");
    list.add(temp2);
    HashMap<String,String> temp3 = new HashMap<String,String>();
    temp3.put("pen","Sailor");
    temp3.put("price", "500.00$");
    temp3.put("color", "Silver");
    list.add(temp3);
    HashMap<String,String> temp4 = new HashMap<String,String>();
    temp4.put("pen","Porsche Design");
    temp4.put("price", "600.00$");
    temp4.put("color", "Silver, Grey, Red");
    list.add(temp4);

}

}

custom_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="match_parent"
android:orientation="vertical" >

<TextView android:id="@+id/text1" 
android:textSize="16sp" 
android:textStyle="bold" 
android:textColor="#FFFF00" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"/>

<TextView android:id="@+id/text2"
android:textSize="12sp" 
android:textStyle="bold" 
android:layout_width="wrap_content" 
android:layout_height="fill_parent"/>

<TextView android:id="@+id/text3" 
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>

  • 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-15T12:19:40+00:00Added an answer on June 15, 2026 at 12:19 pm

    you are 50% done some steps are remaining

    1 remove the constructor for CustomListView. No need of this.

    2 override the onCreate method

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        list = new ArrayList<HashMap<String, String>>();
        populateList();
        SimpleAdapter adapter = new SimpleAdapter(this, list,
                R.layout.custom_list_item, new String[] { "pen", "price",
                        "color" }, new int[] { R.id.text1, R.id.text2,
                        R.id.text3 });
        setListAdapter(adapter);
    }
    

    3 Add your activity in manifest file like

    <activity
            android:name=".CustomListView"
            />
    

    4 How to start from main Activity.you want this on a button click? then you can use Intents

    startActivity(new Intent(yourMainActivity.this,CustomListView.class))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a listview with 3 rows in Android. If I would like
I would like to create a class that runs something (a runnable) at regular
I currently have a custom listview with two rows of text in each item,
I have a custom listView in my app I would like to implement my
I would like to create a ListView in Android where I have the ability
I have a database that I would like class files generated from, and also
I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to
I have a custom listview row that contains a number of textView components. Instead
I would like to create a listview that allows multiple choice. The typical solutions
i would like create a array of structure which have a dynamic array :

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.