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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:01:32+00:00 2026-06-05T08:01:32+00:00

I have loaded data to normal list view from JSON array like this JSONArray

  • 0

I have loaded data to normal list view from JSON array like this

 JSONArray jArray = new JSONArray(result);       
 final String[] array_spinner = new String[jArray.length()];
 for(int i=0;i<jArray.length();i++){
     JSONObject json_data = jArray.getJSONObject(i);
     String jj=json_data.getString("f_name");
     array_spinner[i] = jj;
 }
 ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,  android.R.layout.simple_list_item_1,array_spinner); adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
 //adapter.setDropDownViewResource(R.layout.spinner_layout);
 list.setAdapter(adapter);

I want to load the data to custom listview.
my XML file for custom listview is this
receiver.xml

How can I load data to custom listview from JSON?

  • 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-05T08:01:34+00:00Added an answer on June 5, 2026 at 8:01 am
    • Create a custom Adapter extending BaseAdpter or ArrayAdpter and pass array or ArrayList in the constructor
    • Create the View in a layout (of row)
    • Inflate this xml in getView function of the custom Adapter and set the data

    as in

    http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/

    Populate Listview from JSON

    for you i mixed both to make you understand…

    Activity XML

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

    list row XML (in layout row.xml)

    <?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">
        <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
    
            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtAlertText" />
    
        </LinearLayout>
    </LinearLayout>
    

    you adapter class

    class JSONAdapter extends BaseAdapter implements ListAdapter {
    
        private final Activity activity;
        private final JSONArray jsonArray;
        private JSONAdapter (Activity activity, JSONArray jsonArray) {
            assert activity != null;
            assert jsonArray != null;
    
            this.jsonArray = jsonArray;
            this.activity = activity;
        }
    
    
        @Override public int getCount() {
            if(null==jsonArray) 
             return 0;
            else
            return jsonArray.length();
        }
    
        @Override public JSONObject getItem(int position) {
             if(null==jsonArray) return null;
             else
               return jsonArray.optJSONObject(position);
        }
    
        @Override public long getItemId(int position) {
            JSONObject jsonObject = getItem(position);
    
            return jsonObject.optLong("id");
        }
    
        @Override public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null)
                convertView = activity.getLayoutInflater().inflate(R.layout.row, null);
    
    
    
            TextView text =(TextView)convertView.findViewById(R.id.txtAlertText);
    
                        JSONObject json_data = getItem(position);  
                        if(null!=json_data ){
                        String jj=json_data.getString("f_name");
                        text.setText(jj); 
                       }
    
             return convertView;
        }
    }
    

    your activty

    public class main extends Activity {
        /** Called when the activity is first created. */
    
        ListView lstTest;
        //Array Adapter that will hold our ArrayList and display the items on the ListView
        JSONAdapter jSONAdapter ;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            //Initialize ListView
            lstTest= (ListView)findViewById(R.id.lstText);
    
    
            jSONAdapter = new JSONAdapter (main.this,jArray);//jArray is your json array 
    
            //Set the above adapter as the adapter of choice for our list
            lstTest.setAdapter(jSONAdapter );
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Loaded Data From Datatable to DatagridView which look like this: SerialNumber1 | Quantity
I have CSV data loaded into a multidimensional array. In this way each row
I'm trying to return multiple rows from xml data. I have loaded the result
Forgive me for this basic question. I have loaded a set of data as
I have a large data loaded from a pickled file. The data is a
I have a tooltip with data loaded from ajax: $('.show_tooltip').hover( function(){ $.post('getdata.php', function(data) {
We have a new filestream database that will be initially loaded with 65GB data,
I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data,
I have a ListView bound to ObservableCollection. Data are loaded from the internet and
I have a data table I've loaded from a CSV file. I need to

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.