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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:05:50+00:00 2026-06-16T04:05:50+00:00

I’m developing a simple application in android. I have a list of categories (for

  • 0

I’m developing a simple application in android. I have a list of categories (for now), which I would like to display as a list, and then (but this is far away) on click, start another activity with some functions… well, the situation:

my single_list_item.xml:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <!-- Name Label -->
  <TextView android:id="@+id/category_label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"           
            android:textStyle="bold"
            android:paddingTop="10dip"
            android:paddingBottom="10dip"
            android:textColor="#43bd00"/>
  <!-- Description Label -->

</LinearLayout>

In the main activity here is where I call the adapter and the layout:

List<categorie> values = datasource.getAllCategorie();

        // Use the SimpleCursorAdapter to show the
        // elements in a ListView
        ArrayAdapter<categorie> adapter = new ArrayAdapter<categorie>(this,
            R.layout.single_list_item, values);
        setListAdapter(adapter);

In the Data source here is where I declare the getAllCategorie:

public List<categorie> getAllCategorie() {
            List<categorie> categorie = new ArrayList<categorie>();

            Cursor cursor = database.query(MySQLiteHelper.TABLE_CATEGORIE,
                allCategorieColumns, null, null, null, null, null);

            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
              categorie categoria = cursorToCategorie(cursor);
              categorie.add(categoria);
              cursor.moveToNext();
            }
            // Make sure to close the cursor
            cursor.close();
            return categorie;
          }

and finally the categorie.class :

public class categorie {
      private long id;
      private String nome;
      private long preferita;

      public long getId() {
        return id;
      }

      public void setId(long id) {
        this.id = id;
      }

      public String getNome() {
        return nome;
      }

      public void setNome(String nome) {
        this.nome = nome;
      }



      public long getPreferita() {
        return preferita;
    }

    public void setPreferita(long preferita) {
        this.preferita = preferita;
    }

    // Will be used by the ArrayAdapter in the ListView
      @Override
      public String toString() {
        return nome;
      }
    } 

Currently, if I run the app, it freezes while starting the listview, it makes it completely empty. I would like to specify where to put each category element, such as the name, or the id or if it is “liked” (get and set Preferita in the categorie.class).

When I started, the adapter part was:

ArrayAdapter<categorie> adapter = new ArrayAdapter<categorie>(this,
            android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);

and all was magically OK… why is using a default layout OK? again, where do I specify what goes where?

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-16T04:05:53+00:00Added an answer on June 16, 2026 at 4:05 am

    When you want to implement a simple list, there is no problem using a stock ArrayAdapter. Android looks at the objects you supply to the adapter, calls toString() on those objects and populates a TextView with id=@android:id/text1 with that String. It worked “magically” when you used android.R.layout.simple_list_item_1 because that layout includes a TextView with id=@android:id/text1

    If you want more control over the layout of each row in your ListView, you can use the SimpleAdapter which lets you map values to certain Views in your row layout. Alternatively, you can write your own adapter class by extending ArrayAdapter. I recommend writing your own Adapter, as it is both fun and it gives some insight in how lists are populated. Here’s a guide on how to get started with that.

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

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms

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.