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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:57:22+00:00 2026-06-13T05:57:22+00:00

I need to fill the ListView with AsyncTask. This code works, the TextView changes

  • 0

I need to fill the ListView with AsyncTask.
This code works, the TextView changes to “Begin”, then “End”. But the ListView is blank, not showing. In the log I see “array = 3”.

package a.test3;

import java.util.ArrayList;

import a.test3.MainActivity;
import a.test3.R;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {

    GrabURL mt;
    TextView textView;
    ListView lvMain;
    ArrayList<String> result_arr = new ArrayList<String>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = new TextView(this);
        lvMain = (ListView) findViewById(R.id.listView1);

        mt = new GrabURL();
        mt.execute();
    }

    public class GrabURL extends AsyncTask<Void, Void, ArrayList<String>> {             
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            textView.setText("Begin");
            setContentView(textView);
        }

        @Override
        protected ArrayList<String> doInBackground(Void... params) {
            result_arr.add("a");
            result_arr.add("b");
            result_arr.add("c");
            return result_arr;
        }

        @Override
        protected void onPostExecute(ArrayList<String> result) {
            super.onPostExecute(result);

            Log.d("info", "array = " + result.size());

            textView.setText("End");
            setContentView(textView);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_list_item_1, result);
            lvMain.setAdapter(adapter);
        }
    }
}

Tell me, please, what am I doing wrong?

  • 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-13T05:57:23+00:00Added an answer on June 13, 2026 at 5:57 am

    Look at your code

            textView.setText("End");
            setContentView(textView);
    
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_list_item_1, result_arr);
            lvMain.setAdapter(adapter);
    

    You set View (layout) for your activity. You only display TextView here setContentView(textView);. There’s no ListView lvMain; in your ContentView when you set TextView as a ContentView for your Activity.

    Delete this line

    setContentView(textView);
    

    If it still isn’t working add

    textView.invalidate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get some data to fill a listview control, but this data
I need to know the information when i fill the form and then submit
I've a list List<String> SampleList=new List<String>(); I need to fill a listView with the
I am populating a Listview (list.xml) with a textview (list_row.xml). I need to add
I need to do a ListView that has a single column, where this colum
I need to change the divider color in the listview. The code I am
I just implemented a ListView inside a LinearLayout, but I need to define the
I need bind some ComboBoxes to one ObservableCollection. I have this ListView . <ListView
i've a ListView control with many columns. I need to fill a List<String> with
i've a ListView control like and a Dictionary Dictionary<String,List<String>> MyDict i need to fill

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.