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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:23:14+00:00 2026-06-10T03:23:14+00:00

So I am trying to get a ListView to be populated underneath a button

  • 0

So I am trying to get a ListView to be populated underneath a button on the same layout. Basically when a ListView option is selected the button will respond differently to each selected option. The issue is it is getting a Force close and it seems to be a problem with populating the ListView.

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    >
<Button
    android:background="@drawable/button"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp" 
    android:layout_gravity="center"
    android:id="@+id/button"/>

    <ListView
    android:listSelector="#990000"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="10dp"
    android:id="@+id/listview"
    />
</LinearLayout>

Code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    lv = (ListView) findViewById(R.id.listview);

    ArrayList<String> list = new ArrayList<String>();
    soundsList.add("one");
soundsList.add("two");
soundsList.add("three");



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

The Logcat readout is this:

08-23 10:21:23.735: ERROR/AndroidRuntime(588): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I have tried exactly what it says in the ArrayAdapter… (android.R.id.list. I’ve tried numerous other things including an extends ListActivity, but regardless of what I try I seem to get a similar Logcat response.

Is there a better way to pull off what I am trying to accomplish? I want the button above the ListView all on the same main.xml.

Thanks in advance.

EDIT:

I had also tried this code. Currently commented out, but it was what I tried originally.

setListAdapter(new ArrayAdapter<String>(this, android.R.id.list,LIST));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);

LIST is a Strings array. The output on Logcat from the above code was the same as the previous.

  • 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-10T03:23:16+00:00Added an answer on June 10, 2026 at 3:23 am

    Sounds like you are either trying to implement a ListActivity or a ListFragment, which expects to find a listview instance with a specific name, hence the error. Try changing the id of your listview from:

    android:id="@+id/listview"
    

    to:

    android:id="@android:id/list"
    

    I know that you said that you already tried this, but given your code, it looks like its still wrong. Once you change it can you post the new error message? I realize according to your description that it’s going to be a similar message, but even if the difference is slight it’s probably still significant.

    EDIT:

    Another thing I just noticed – if you are indeed using ListActivity or FragmentActivity, get a ref to the ListView by calling getListView() instead offindViewById()`.

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

Sidebar

Related Questions

I'm trying to get the value of each selected item in a list view.
I am trying to create a ListView that will be populated with the entries
I am trying to get position inside a fling for a listview. No matter
I have a listview that I'm populating with data and I'm trying to get
I am just trying to fill my ListView but I get a NullPointerException Here
trying to get same string on tooltip as is in the Text e.g. Text=<%#
I'm trying to filter my ListView which is populated with this ArrayAdapter: package me.alxandr.android.mymir.adapters;
I'm trying to get images to display in a WPF ListView styled like a
I'm trying to drag an item between two Groups in the same ListView called
I'm using a script from a ListView tutorial and am trying to get some

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.