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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:34:23+00:00 2026-06-11T06:34:23+00:00

I want to get an image from my database mySQL to show in listview

  • 0

I want to get an image from my database mySQL to show in listview (image + text listview)

my code :

       public void cek(){

           String url_select = "http://10.0.2.2/BloodGlucose/selectDoctor.php";

           HttpClient httpClient = new DefaultHttpClient();
           HttpPost httpPost = new HttpPost(url_select);

           //parameter
           ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();

           try {
              //add parameter
               httpPost.setEntity(new UrlEncodedFormEntity(param));

             HttpResponse httpRespose = httpClient.execute(httpPost);
             HttpEntity httpEntity = httpRespose.getEntity();

             //read content
             InputStream in = httpEntity.getContent();
             BufferedReader read = new BufferedReader(new InputStreamReader(in));

             String content = "";
             String line = "";

             while((line = read.readLine())!=null){
                content += line;
             }

             Log.d("ADBUG", "content: "+content);


             //json
             if(!content.equals("null")){




                try {
                   JSONArray jArr = new JSONArray(content);
                   for(int i=0;i<jArr.length();i++){
                      JSONObject jObj = jArr.getJSONObject(i);
                      String id = jObj.getString("_id");
                      String name = jObj.getString("name");
                      String dateofbirth = jObj.getString("dateofbirth");
                      String phone = jObj.getString("telp");
                      String address = jObj.getString("clinicaddress");
                      String file = jObj.getString("file");
                      String uname = jObj.getString("username_doctor");
                      String lulusan = jObj.getString("lulusan");
                      String clinicname = jObj.getString("clinicname");

                      names.add(name);
                      date.add(dateofbirth);
                      telp.add(phone);      
                      clinic.add(address);
                      usernamedoctor.add(uname);
                      namaklinik.add(clinicname);
                      graduate.add(lulusan);



                   }



setListAdapter(new DoctorArrayAdapter(this, names)); 

                } catch (JSONException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                }

             }else{
                Toast.makeText(this, "Error", Toast.LENGTH_LONG).show();
             }

          } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }
       }

DoctorArrayAdapter code:

package research.android.bloodglucose;


import java.util.ArrayList;

import research.android.bloodglucose.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DoctorArrayAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final ArrayList<String> values;

    public DoctorArrayAdapter(Context context, ArrayList<String> names) {
        super(context, R.layout.list_row, names);
        this.context = context;
        this.values = names;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.list_row, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.DoctorName);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.list_image);
        textView.setText(values.get(position));

        // Change icon based on name
        String s = values.get(position);

        System.out.println(s);

        /*if (s.equals("WindowsMobile")) {
            imageView.setImageResource(R.drawable.windowsmobile_logo);
        } else if (s.equals("iOS")) {
            imageView.setImageResource(R.drawable.ios_logo);
        } else if (s.equals("Blackberry")) {
            imageView.setImageResource(R.drawable.blackberry_logo);
        } else {
            imageView.setImageResource(R.drawable.android_logo);
        }*/

        return rowView;
    }
}

is there any something wrong with my code? because the image didn’t show, it’s only the text, thank you very much

  • 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-11T06:34:25+00:00Added an answer on June 11, 2026 at 6:34 am

    Handy, You should create a class that extends from ArrayAdapter, then you implement the method getView to tell your list what to do on each item (add the image and the text).

    check this link Android listview example

    (the Custom ArrayAdapter example)

    (And one tip, your error part comes from building a listview not from fetching the data from MySQL so remove this part from your question it’s misleading)

    This is a function to get the image having its url path

    public static Bitmap getURLImage(String path)
    {
    
        try
        {
            URL aURL = new URL(path);
            final URLConnection conn = aURL.openConnection();
            conn.connect();
            final BufferedInputStream bis = new BufferedInputStream(
                    conn.getInputStream());
            final Bitmap bm = BitmapFactory.decodeStream(bis);
            bis.close();
            return bm;
        }
        catch (Throwable e)
        {   
            Log.w("ERROR", "Error " + e.getMessage());
            return null;
        }
    }
    

    then you do (you should call it from a thread, because since android 4.0 you’re not allowed to make a network connection from the main thread, This is the part that should be added in getView):

        new Thread() {
                    public void run() {
                        try {
                            //mBitmap is an attirbute
                            mBitmap = getRemoteImage(link);
                            handler.sendEmptyMessage(COMPLETE);
    
                        } finally {
    
                        }
                    };
                };
    
    
    
    /**
    in your handler u set the image to the bitmap that you fetched
    */
        private final Handler handler = new Handler(new Callback() {
    
                public boolean handleMessage(Message msg) {
                       imageView.setImageBitmap(mBitmap);
                }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want just get Image( .JPG , .PNG , .Gif ) File from my
I want to get a thumbnail image for videos from Vimeo. When getting images
I want to get the currently selected item (text, image, etc) and display in
Is it possible to get the height of a 'text' field from mysql? Or
I am using WAMP. I want to take background image URL from my database
I have printed the table get from database like below And my code print
I want to get some images from a movie and make a gif. What
I want to get some images from a flash webpage and I got the
I want to get the Bitmap from URL like - https://graph.facebook.com/100003506521332/picture I tried how-i-can-display-images-from-url-in-blackberry
I want to get this image uploading script right, but for whatever reason it

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.