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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:02:14+00:00 2026-06-14T05:02:14+00:00

I have written some code to set data to listview from a webpage. I

  • 0

I have written some code to set data to listview from a webpage. I have read the webpage successfully and stored necessary data in String array. Now i want to assign that to ListView using ArrayAdapter but the data is not getting set in listview. Please help me solve the error:

Output of logcat so as to verify that data is being stored in String array

11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies
11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly
11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfies
11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly
11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies
11-07 23:03:47.640: I/VALUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies<br/>Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly<br/>Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfies<br/>Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly<br/>Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies

CODE

private Spinner spinner1;
private ProgressDialog pd;
private StringBuilder response;
private ListView listView;
private String[] values = new String[0];
private ArrayAdapter<String> adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (ListView) findViewById(R.id.mylist);
    spinner1 = (Spinner) findViewById(R.id.spinnerCategory);
    spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> av, View view, int id,
                long ids) {
            new sendMessageAsync().execute();
        }

        public void onNothingSelected(AdapterView<?> av) {
        }
    });

    adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, values);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

private class sendMessageAsync extends AsyncTask<Void, Void, String> {

    @Override
    protected void onPreExecute() {
        pd = ProgressDialog.show(main.this, null, "Loading...",
                true, true);
    }

    @Override
    protected void onCancelled() {
        Toast.makeText(getApplicationContext(),
                "Message Sending Cancelled", Toast.LENGTH_LONG).show();
    }

    @Override
    protected String doInBackground(Void... arg0) {
        try {
            doInBg();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        pd.dismiss();
        adapter.notifyDataSetChanged();
        listView.setAdapter(adapter);
    }
}

public void doInBg() {
    try {
        final String msgURL = "http://example.com/messages.php?category=" + String.valueOf(spinner1.getSelectedItem().toString().replace(" ", "%20"));
        URLConnection connection = new URL(msgURL).openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        InputStream responseStream = connection.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(responseStream));
        response = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            response.append(line);
        }
        values = String.valueOf(response).split("<br/>");
        for (int i = 0; i < values.length;i++) {
            Log.i("NEW VAUES", values[i]);
        }
        Log.i("VALUES", String.valueOf(response));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
  • 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-14T05:02:17+00:00Added an answer on June 14, 2026 at 5:02 am

    You’re not changing the array the adapter stores. When you do:

    values = String.valueOf(response).split("<br/>");
    

    You are storing a new array in your class member, but your adapter still holds the old array. You can create and set a new adapter, but this solution is not good for performance. Instead, you must add each item to the adapter from this new array. Try this:

    private class sendMessageAsync extends AsyncTask<Void, Void, String> {
    
        @Override
        protected void onPreExecute() {
            pd = ProgressDialog.show(main.this, null, "Loading...",
                    true, true);
        }
    
        @Override
        protected void onCancelled() {
            Toast.makeText(getApplicationContext(),
                    "Message Sending Cancelled", Toast.LENGTH_LONG).show();
        }
    
        @Override
        protected String doInBackground(Void... arg0) {
            try {
                return doInBg();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(String result) {
            pd.dismiss();
            if (result == null) {
                // request failed!
                // return;
            }
            values = String.valueOf(result).split("<br/>");
            adapter.clear();
            for (String str : values)
                adapter.add(str);
        }
    }
    
    public String doInBg() {
        try {
            final String msgURL = "http://example.com/messages.php?category=" + String.valueOf(spinner1.getSelectedItem().toString().replace(" ", "%20"));
            URLConnection connection = new URL(msgURL).openConnection();
            connection.setRequestProperty("Accept-Charset", "UTF-8");
            InputStream responseStream = connection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(responseStream));
            response = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                response.append(line);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return response;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code using jQuery to use Ajax to get data from
I have written a T-SQL script that migrates some data from one database to
I have written some code that pulls info from a plist file and does
I have written some code that loads an XML document using an XmlDocument object
I have written some code for displaying a drop down list, but the code
I have written some code in JSP to download .docx files which is hosted
I have written some code for playing a .wav through my application. Now I
I have written some code to ensure that items on an order are all
I have written some code to look at properties using reflection. I have retrieved
I have written some code to display a YouTube video on my page but

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.