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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:19:15+00:00 2026-06-10T16:19:15+00:00

As the title says, I have a mySQL database that has data on it.

  • 0

As the title says, I have a mySQL database that has data on it. I want my android app to retrieve that data and insert it into a ListView. I don’t think I’m doing it correctly because my current code; although not producing any errors, doesn’t work. Here is my code:

http://pastebin.com/sZy5dAzS

I’d just like to point out that when I insert that data into a TextView it shows up on my app just fine. So it must be that I’m doing something wrong with my ListView. I just don’t know what.

Just to make it easier to read these are the parts of my ListView:

At the top of my code

List<String> nameData = new ArrayList<String>();

The for loop for my JSON Parsing:

            try {
                jArray = new JSONArray(result);
                JSONObject json_data = null;
                currentList = (ListView) findViewById(R.id.list);



                for (int i = 0; i < jArray.length(); i++) {

                    json_data = jArray.getJSONObject(i);
                    nameData.add(drivername = json_data.getString("Driver_full_name"));
                    nameData.add(drivesfor = json_data.getString("Drives_for"));

                }

I do have a catch here as you can see in the pastebin link, just haven’t posted it.

and the onPostExecute

protected void onPostExecute(String output){

        currentList.setAdapter(new ArrayAdapter<String>    (CurrentSeasonDrivers.this, android.R.layout.simple_list_item_2, nameData));
        Toast.makeText(CurrentSeasonDrivers, "DONE!",     Toast.LENGTH_LONG).show();

    }

Just to reiterate; a TextView works fine when pulling the data so the rest of the code is correct.

Really appreciate any help given. Thanks.

  • 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-10T16:19:16+00:00Added an answer on June 10, 2026 at 4:19 pm

    I am not sure what the exact problem is in your code but I have a feeling it has to do with your adapter. I have suggestion on a way to do it that should work and that is better and more flexible which is basically creating your own adapter.

    First make a small Driver class which will be used as the source of data

    public class DriverItem {
    
        private String name;
        private String driversFor;
    
        public DriverItem(String n, String d) {
            super();
            this.name = n;
            this.driversFor = d;
        }
    
        // Getter and setter methods for all the fields.
        public String getName() {
            return name;
        }
    
        public String getDriversFor() {
            return driversFor;
        }
    

    }

    Now create the adapter which will be used for creating the views

    public class DriverListItemAdapter extends BaseAdapter {
        private List<DriverItem> listDriverItem;
        private Context context;
    
        public DriverListItemAdapter(Context ctx, List<DriverItem> list)
        {
            context = ctx;
            listDriverItem = list;
        }
    
        public int getCount() {
            // TODO Auto-generated method stub
            listDriverItem.size();
        }
    
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return listDriverItem.get(position);
        }
    
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            // TODO Auto-generated method stub
            DriverItem driver = listDriverItem.get(position);
    
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            convertView = inflater.inflate(R.layout.list, null);
            TextView name = (TextView)convertView.findViewById(R.id.txtName);
            name.setText(driver.getName());
    
            return convertView
        }
    }
    

    Now you need the view which will be used to display each listview row

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
    
        <TextView
            android:id="@+id/txtName"
            android:layout_height="wrap_parent"
            android:layout_width="fill_parent" 
            />
    </LinearLayout>
    

    And now in your code you simply create the arraylist of drivers, create an adapter out of that, and set that adapter on your listview.

    DriverListItemAdapter adapter;
    ListView currentList = (ListView) findViewById(R.id.list);
    ArrayList<DriverItem> listOfDriverListItem;
    
    for(int i = 0; i < jArray.length(); i++){
                jObj = jArray.getJSONObject(i);        
                listOfDriverListItem.add(newDriverItem(jObj.getString("Driver_full_name"),jObj.getString("Drives_for")));
            }
    
    adapter = new DriverListItemAdapter(this, listOfDriverListItem);
    currentList.setAdapter(adapter);
    

    You should be able to just copy paste the all of these things into their own classes and it should work.. and replace your listview code with the one I gave at the bottom..
    This should work, let me know if you have any questions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

as the title says, I want to Insert into table 3 (list_mail_usr) all the
I just want what my title says.I have already read all the previous similar
The title says it mostly. If I have an object in Python and want
Ok, so as the title says, I have an HTML page that I fetch
As the title says I have a list of Django objects and I want
-- Hello, just ast the title says. I have a downloader class that I
I have created a java SE application that uses the mysql database using mysql
As the title says, I have a method that throws a NullReferenceException in my
Basically what the title says... I need to have an image that when clicked,
as the title says, is there a way I can have a clock that

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.