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

  • Home
  • SEARCH
  • 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 7722083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:05:07+00:00 2026-06-01T04:05:07+00:00

Im trying to add a list view to my activity. Here is what is

  • 0

Im trying to add a list view to my activity. Here is what is suppose to happen:
The user clicks on a button and that uses an asyncTask to get data from the internet. That data should then be added to the list view. The data comes from a table online therefore it there are 10 rows in the table then there should be 10 values in the Listview.

  1. But I’m having some problems.
    First of all can a listview be added to a pre-existing layout and be updated on the fly?

  2. Does a list view mean you cannot use the setContentView() method and have to use setListAdapter?

  3. If you have a layout that already has two buttons arranged on it can the list view be added in below them and still be implemented using the setContentView() method?

Thanks

Edit

Updated Code – Which works:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView( R.layout.new_sightings );

    ListView list = getListView();
    list.setAdapter( new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, values ) );
    list.setTextFilterEnabled( true );
}

XML Layout

?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation = "vertical">

  <TableLayout

android:layout_width = "fill_parent"
android:layout_height = "wrap_content"  
  >

  <TableRow

android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"
  >

  <TextView

android:id = "@+id/txtTitle"
android:layout_width = "wrap_content"
android:layout_height = "fill_parent"
android:layout_weight = "1"
android:gravity = "center"
android:text = "ISS Predictions" 
android:textStyle="bold"
android:textColor = "#FFFFFF"
    />

  <Button 
android:id="@+id/reloadTen" 
android:layout_height="wrap_content" 
android:layout_width ="fill_parent"
android:layout_gravity = "right"
android:layout_weight = "1"
android:text = "Reload"
android:textColor = "#FFFFFF"
android:textStyle = "bold"
android:background = "#000000"
/>

  </TableRow>

  </TableLayout>

   <ListView

android:id = "@+id/android:list"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textSize = "15dp"
android:textStyle = "bold"

  />


</LinearLayout>
  • 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-01T04:05:08+00:00Added an answer on June 1, 2026 at 4:05 am

    1) Yes, you can have a ListView in your layout, and update the data displayed by the ListView. Typically you’d make a class that inherits from ArrayAdapter to bridge the gap between your underlying data and generating views for your ListView.

    When you want to update the data displayed, use add() and notifyDataSetChanged() on your adapter.

    2) No. You call setListAdapter() only when your activity inherits from ListActivity and you have a ListView element with an id of @android:id/list. Here’s an example of such an element:

    <ListView android:id="@android:id/list"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:layout_weight="1"/>
    

    You still use setContentView() to pass in the desired XML layout to use.

    3) Yes, for the reasons explained above.

    • 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 a user input from Edit Text into List View, I
I'm trying to use a list view, and when I add an item to
I am trying to get text of list view item. And I am making
Hi I've been having some trouble trying to get a list view I created
I'm trying to add items to a list view in a different thread than
I'm trying to add a RelativeLayout, that contains 2 TextViews, above a ListView as
I´m trying to add a list to a table cell but there are no
So I am trying to add a list of ticker symbols from a CSV
Trying to add init parameter names to a list in init(ServletConfig) method. public void
Trying to add a class object into a List using reflection, but when invoking

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.