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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:21:40+00:00 2026-06-16T20:21:40+00:00

I new to android programming. I would like to know how to parse a

  • 0

I new to android programming. I would like to know how to parse a webpage and extract specific content into a ListView. What is the easiest and best way to do it? Can someone show me an example using what’s given below?

URL = “Something.com”.

I want to extract the names of the cities and href link for each one.

ann arbor
battle creek
central michigan
detroit metro
flint
grand rapids

Thank you guys and sorry for asking this basic question.

  • 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-16T20:21:42+00:00Added an answer on June 16, 2026 at 8:21 pm

    look the code below and let me know if you have any doubts and see this link it may help you

    http://wptrafficanalyzer.in/blog/android-lazy-loading-images-and-text-in-listview-from-http-json-data/

    public class MainActivity extends Activity {
    
        ListView mListView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // URL to the JSON data
            String strUrl = "ur url/countries";
    
            // Creating a new non-ui thread task to download json data
            DownloadTask downloadTask = new DownloadTask();
    
            // Starting the download process
            downloadTask.execute(strUrl);
    
            // Getting a reference to ListView of activity_main
            mListView = (ListView) findViewById(R.id.lv_countries);
    
        }
    
        /** A method to download json data from url */
        private String downloadUrl(String strUrl) throws IOException{
            String data = "";
            InputStream iStream = null;
            try{
                URL url = new URL(strUrl);
    
                // Creating an http connection to communicate with url
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    
                // Connecting to url
                urlConnection.connect();
    
                // Reading data from url
                iStream = urlConnection.getInputStream();
    
                BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
    
                StringBuffer sb  = new StringBuffer();
    
                String line = "";
                while( ( line = br.readLine())  != null){
                    sb.append(line);
                }
    
                data = sb.toString();
    
                br.close();
    
            }catch(Exception e){
                Log.d("Exception while downloading url", e.toString());
            }finally{
                iStream.close();
            }
    
            return data;
        }
    
        /** AsyncTask to download json data */
        private class DownloadTask extends AsyncTask<String, Integer, String>{
            String data = null;
            @Override
            protected String doInBackground(String... url) {
                try{
                    data = downloadUrl(url[0]);
                }catch(Exception e){
                    Log.d("Background Task",e.toString());
                }
                return data;
            }
    
            @Override
            protected void onPostExecute(String result) {
    
                // The parsing of the xml data is done in a non-ui thread
                ListViewLoaderTask listViewLoaderTask = new ListViewLoaderTask();
    
                // Start parsing xml data
                listViewLoaderTask.execute(result);
            }
        }
    
        /** AsyncTask to parse json data and load ListView */
        private class ListViewLoaderTask extends AsyncTask<String, Void, SimpleAdapter>{
    
            JSONObject jObject;
            // Doing the parsing of xml data in a non-ui thread
            @Override
            protected SimpleAdapter doInBackground(String... strJson) {
                try{
                    jObject = new JSONObject(strJson[0]);
                    CountryJSONParser countryJsonParser = new CountryJSONParser();
                    countryJsonParser.parse(jObject);
                }catch(Exception e){
                    Log.d("JSON Exception1",e.toString());
                }
    
                // Instantiating json parser class
                CountryJSONParser countryJsonParser = new CountryJSONParser();
    
                // A list object to store the parsed countries list
                List<HashMap<String, Object>> countries = null;
    
                try{
                    // Getting the parsed data as a List construct
                    countries = countryJsonParser.parse(jObject);
                }catch(Exception e){
                    Log.d("Exception",e.toString());
                }
    
                // Keys used in Hashmap
                String[] from = { "country"
    
                // Ids of views in listview_layout
                int[] to = { R.id.tv_country};
    
                // Instantiating an adapter to store each items
                // R.layout.listview_layout defines the layout of each item
                SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), countries, R.layout.lv_layout, from, to);
    
                return adapter;
            }
    
            /** Invoked by the Android on "doInBackground" is executed */
            @Override
            protected void onPostExecute(SimpleAdapter adapter) {
    
                // Setting adapter for the listview
                mListView.setAdapter(adapter);
    
                for(int i=0;i<adapter.getCount();i++){
                    HashMap<String, Object> hm = (HashMap<String, Object>) adapter.getItem(i);
                                       HashMap<String, Object> hmDownload = new HashMap<String, Object>();
                    hm.put("flag_path",imgUrl);
                    hm.put("position", i);
    
    
                }
            }
        }
    
                 @Override
            protected void onPostExecute(HashMap<String, Object> result) {
                // Getting the path to the downloaded image
                String path = (String) result.get("flag");
    
                // Getting the position of the downloaded image
                int position = (Integer) result.get("position");
    
                // Getting adapter of the listview
                SimpleAdapter adapter = (SimpleAdapter ) mListView.getAdapter();
    
                // Getting the hashmap object at the specified position of the listview
                HashMap<String, Object> hm = (HashMap<String, Object>) adapter.getItem(position);
    
                // Overwriting the existing path in the adapter
                hm.put("flag",path);
    
                // Noticing listview about the dataset changes
                adapter.notifyDataSetChanged();
            }
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am new to android programming and i would like to know how
I'm new to Android programming. I would like to know if I can load
I'm fairly new to Java and Android programming in general but I would like
I'm new to android programming. I would like to make an app widget that
Hello I'm new to android programming. I would like to ask how can I
I’m new in android programming I’m working on database application I would like to
I'm new to any sort of programming for networks, and would like a little
I'm new to Android application development. I would like to ask the use of
I'm very new to Android Programming, It would be really great if someone can
I'm new to Android and the Java programming language but I know what application

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.