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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:07:07+00:00 2026-06-04T23:07:07+00:00

i want to display images from mysql server(testing in localhost) using imageurl,i have images

  • 0

i want to display images from mysql server(testing in localhost) using imageurl,i have images in a filder on my server,in an android client app as gridview along with text.how do i use imageurl in my code?
mymainmenu.java

public class MainMenu extends Activity {



    GridView gridView;

    static final String[] MOBILE_OS = new String[] { 
        "Android", "iOS","Windows", "Blackberry" };

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu_list);


        gridView = (GridView) findViewById(R.id.gridView1);

        gridView.setAdapter(new ImageAdapter(this, MOBILE_OS));

        gridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                Toast.makeText(
                   getApplicationContext(),
                   ((TextView) v.findViewById(R.id.grid_item_label))
                   .getText(), Toast.LENGTH_SHORT).show();

            }
        });

    }

}

my imageadapter.java:

public class ImageAdapter extends BaseAdapter {
private Context context;
private final String[] mobileValues;
    public ImageAdapter(Context context, String[] mobileValues) {
    this.context = context;
    this.mobileValues = mobileValues;
}

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    if (convertView == null) {

        gridView = new View(context);

        // get layout from list.xml
        gridView = inflater.inflate(R.layout.list, null);

        // set value into textview
        TextView textView = (TextView) gridView
                .findViewById(R.id.grid_item_label);
        textView.setText(mobileValues[position]);

        // set image based on selected text
        ImageView imageView = (ImageView) gridView
                .findViewById(R.id.grid_item_image);

        String mobile = mobileValues[position];

        if (mobile.equals("Windows")) {
            imageView.setImageResource(R.drawable.imggrid);
        } else if (mobile.equals("iOS")) {
            imageView.setImageResource(R.drawable.imggrid);
        } else if (mobile.equals("Blackberry")) {
            imageView.setImageResource(R.drawable.imggrid);
        } else {
            imageView.setImageResource(R.drawable.imggrid);
        }

    } else {
        gridView = (View) convertView;
    }

    return gridView;
}

@Override
public int getCount() {
    return mobileValues.length;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

}

I dnt know how to use the following in my code:

try {
            URL url = new URL(imageFileURL);
            URLConnection conn = url.openConnection();                   
            HttpURLConnection httpConn = (HttpURLConnection)conn;
            httpConn.setRequestMethod("GET");
            httpConn.connect();               
            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
             InputStream inputStream = httpConn.getInputStream();                     
             Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
             inputStream.close();
             img.setImageBitmap(bitmap);
            }
           } catch (MalformedURLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
           } catch (IOException e) {
            // TODO Auto-generated catch block
            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-06-04T23:07:08+00:00Added an answer on June 4, 2026 at 11:07 pm

    Put the image downloading code in a AsyncTask. Here is the explanation.
    Execute one instance of asynctask in your getView method, i.e to fetch one image everytime.

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
     ImageView mImageView;
     public void setImageView(ImageView img) {
          mImageView = img;
     }
    
     protected Bitmap doInBackground(String... urls) {
         return loadImageFromNetwork(urls[0]);
     }
    
     protected void onPostExecute(Bitmap result) {
         mImageView.setImageBitmap(result);
     }
    

    }

    Call task.setImageView(yourImageViewinGrid) before executing your AsyncTask to let it know where to set the image after downloading.

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

Sidebar

Related Questions

I am using the Gallery3D -Code but want it to only display images from
I want to display images on a .net page which I load from database
I am parsing the public timeline xml from twitter and want to display images
I want to get a list of product images from SQL to display in
I want to download image from server and display them into a layout EXAMPLE
I want to display a simple GIF image in a VBox using GTK+ from
I have n Arrays with Images and I want to display images correspondingly in
I have a page where I want to display different images based on the
Hy. I want to display pictures from my mysql data base. Php Code: <body>
I want to extract images from the_content() and want to display first images from

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.