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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:45:45+00:00 2026-06-15T13:45:45+00:00

i have an app in which i want to fill the ListView by data

  • 0

i have an app in which i want to fill the ListView by data from SQLite Database…in this part i have an problem, with arrayAdapter…

here is my code of the method for fill the listView:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    PetListView = (ListView)findViewById(R.id.list);


    MyDatabaseHelper db = new MyDatabaseHelper(this);
    String [] items = new String[100];


    List<Pet> pets = db.getAllPets();
    for (int i = 0; i < 10; i++) {
        items[i] = pets.get(i).getName();                   
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.activity_list_item, R.id.textView1list, items);
    PetListView.setAdapter(adapter);

}

and this is method implemented in my database helper:

public List<Pet> getAllPets() {
    List<Pet> petList = new ArrayList<Pet>();
    String selectQuery = "SELECT * FROM " + TABLE_PETS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            Pet pet = new Pet();
            pet.setID(Integer.parseInt(cursor.getString(0)));
            pet.setName(cursor.getString(1));
            pet.setAge(cursor.getString(2));
            petList.add(pet);
        } while (cursor.moveToNext());
    }
    cursor.close();
    return petList;     
}

Why textView? I’m only using ListView…

Can you anybody tell me any other way how to fill the listView by data(names) from SQLite?

  • 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-15T13:45:46+00:00Added an answer on June 15, 2026 at 1:45 pm

    use

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
              android.R.layout.activity_list_item, android.R.id.text1, items);
    

    instad of

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
                android.R.layout.activity_list_item, R.id.textView1list, items);
    

    use android.R.id.text1 as TextView id if you are using default activity_list_item layout for ListView

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

Sidebar

Related Questions

This is my first question. I have an app in which i want to
I have a listview which I want to display custom data like zodiac Sign
I have a ListView (in WPF app) which I fill it programmatically: l1.Items.Add(new {
I have a .exe app which I want to understand better - I can
I have app in which i have recorded sound files i want that i
I have a UIWebView in my app which I want to use to display
I have an App in which i have an URL, I dont want to
I'm developing a ASP.Net MVC3 app which will have few hundred videos. I want
I want to develop an Android app in which I have key log press.
I have an app version 1.0 which is on Appstore, now I want to

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.