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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:23:22+00:00 2026-05-31T06:23:22+00:00

Hi I have created an activity which pulls data from json format text and

  • 0

Hi I have created an activity which pulls data from json format text and displays in a spinner view. But im a little confused with the last part. The contactList is a ArrayList type, ArrayAdapter is not accepting contactList as its arugument.
Is
Here’s my code

 public class RegisterForEventActivity extends Activity {

        private static String url = "http://10.0.2.2/Contacts.txt";
        private static final String TAG_NAME = "name";
        private static final String TAG_CONTACTS = "contacts";

        JSONArray jsonArray = null;

        Spinner areaspinner;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.register_layout);


         // Hashmap for ListView
            ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

                // Creating JSON Parser instance
                JSONParser jParser = new JSONParser();

                // getting JSON string from URL
                JSONObject json = jParser.getJSONFromUrl(url);

                try {
                    // Getting Array of Contacts
                    jsonArray = json.getJSONArray(TAG_CONTACTS);

                    final String[] array_spinner = new String[jsonArray.length()]; 

                    // looping through All Contacts
                    for(int i = 0; i < jsonArray.length(); i++){

                        JSONObject c = jsonArray.getJSONObject(i);

                        // Storing each json item in variable
                        String name = c.getString(TAG_NAME);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_NAME, name);


                        // adding HashList to ArrayList
                        contactList.add(map);

ArrayAdapter<String> adapter = 
                                new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, contactList);       
                        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        areaspinner.setAdapter(adapter);
                    }

                } catch (JSONException e) {
                    e.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-05-31T06:23:23+00:00Added an answer on May 31, 2026 at 6:23 am

    Yes, I figured it out!

    sp=(Spinner)findViewById(R.id.spinner1);
    
         // Hashmap for ListView
    
    
                // Creating JSON Parser instance
                JSONParser jParser = new JSONParser();
    
                // getting JSON string from URL
                JSONObject json = jParser.getJSONFromUrl(url);
                System.out.println("Hello");
                try {
                    // Getting Array of Contacts
                    jsonArray = json.getJSONArray(TAG_CONTACTS);
    
                    final String[] items = new String[jsonArray.length()]; 
    
                    // looping through All Contacts
                    for(int i = 0; i < jsonArray.length(); i++){
    
                        JSONObject c = jsonArray.getJSONObject(i);
                        // Storing each json item in variable
    
                        String name = c.getString(TAG_NAME);
    
    
                        items[i]=c.getString(TAG_NAME);
                        System.out.println("Hello events "+items);
                    }
    
                    ArrayAdapter<String> adapter = 
                            new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, items);       
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    sp.setAdapter(adapter);
    
                } catch (JSONException e) {
                    e.printStackTrace();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some business objects which are created with the data from the
I have created an activity which sends a number of notifications to status bar.
I have created a custom workflow activity that copies attachments from a case to
I have created an Activity with a AutuCompleteTextView[ACTV] and button. I enter some text
I have created an abstract class which extends the Activity Class. I want to
I have in my DBAdapter, a getAll which should pull all the data from
I have created an application having tab activity which in turn has 5 different
I have created Workflow and I have my code activity which is doing expensive
I have created an abstract class FbActivity, which extends Activity to connect to facebook
I am new to Android development. I have created a main Activity (->A), which

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.