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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:23:11+00:00 2026-06-11T10:23:11+00:00

i have a listview and its data values is separated by blocks( Item1, Item2…)

  • 0

i have a listview and its data values is separated by blocks( Item1, Item2…) but i want to know how to show (Item 1, Sub Item 1…) ?
well here is the code that shows only the Item, so how do i show the Item and the Sub Item?

code:

           //LISTVIEW database CONTATO
    ListView user = (ListView) findViewById(R.id.lvShowContatos);
    //String = simple value ||| String[] = multiple values/columns
    String[] campos = new String[] {"nome", "telefone"};

    list = new ArrayList<String>();
    Cursor c = db.query( "contatos", campos, null, null, null, null, "nome" + " ASC ");
    c.moveToFirst();
    String lista = "";
    if(c.getCount() > 0) {
        while(true) {
           list.add(c.getString(c.getColumnIndex("nome")).toString());
            if(!c.moveToNext()) break;
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, list);

    user.setAdapter(adapter);

the code i putted there but still gives me errors and i dont see where it gets the values from yet.

             //LISTVIEW database CONTATO
    ListView user = (ListView) findViewById(R.id.lvShowContatos);
    //String = simple value ||| String[] = multiple values/columns
    String[] campos = new String[] {"nome", "telefone"};


    ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String,Object>>();
    HashMap<String, Object> listItem;

    Cursor c = db.query( "contatos", campos, null, null, null, null, "nome" + " ASC ");
    c.moveToFirst();

    listItem = new HashMap<String, Object>();
    listItem.put("nome", "your_item_text");
    listItem.put("telefone", "your_subitem_text");
    items.add(listItem);

    adapter = new SimpleAdapter(this, items, R.layout.custom_list_layout, new String[]{"item", "subitem"}, new int[]{R.id.text_item, R.id.text_subitem});

    user.setAdapter(adapter);
  • 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-11T10:23:12+00:00Added an answer on June 11, 2026 at 10:23 am

    Use SimpleAdapter, not the ArrayAdapter to populate the ListView: http://developer.android.com/reference/android/widget/SimpleAdapter.html
    There you will have an array of fields to populate for each item, like:

    ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String,Object>>();
    HashMap<String, Object> listItem;
    
    listItem = new HashMap<String, Object>();
    listItem.put("item", "your_item_text");
    listItem.put("subitem", "your_subitem_text");
    items.add(listItem);
    
    adapter = new SimpleAdapter(this, items, R.layout.custom_list_layout, new String[]{"item", "subitem"}, new int[]{R.id.text_item, R.id.text_subitem});
    
    listview.setAdapter(adapter);
    

    Remember also to create custom_list_layout.xml for your ListView items, and make sure it contains textViews with proper ids:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <TextView
            android:id="@+id/text_item"
            ... />
    
        <TextView
            android:id="@+id/text_subitem"
            ... />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with Horizontal WrapPanel as its ItemsPanelTemplate. I want to get
I have a listview which loads its data from sqlite database. Each row in
I have a Listview inside a Scrollview and manually binding its data on the
I have a listview with database data and its working all fine and perfect
The main concept goes like this. I have four listviews with its own data
I have a listview which has its datasource changed after update of a search
HI Guyz i have created a sectioned custom listview using baseadapter its working fine
i have implemented a list view its working fine but when i click on
I have a listview control, and it's data refreshing continously. I'd like to 'put'
I have a listview where each item correlates to an instance of an item

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.