user6639890
user6639890

Reputation:

How to get Image from database and set in ImageView?

i want to fetch Image from the database and set in the ImageView? I tried a lot but not getting the output

Here I tried this way to fetch Image :-

  private class fetchprofile extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(getActivity());
        mProgressDialog.setTitle("Please Wait");
        // Set progressdialog message
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }
    @Override
    protected Void doInBackground(Void... args) {

        try {
            arraylist = new ArrayList<HashMap<String, String>>();

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("at_username", uid));

            JSONObject json = jParser.makeHttpRequest(url_visitor, "GET", params);

            ownerObj = json.getJSONArray("profile");
            for (int i = 0; i < ownerObj.length(); i++) {
                // uid= json.getJSONArray("v_parties").getJSONObject(0).getString("count");
                jsonobject = ownerObj.getJSONObject(i);
                img="http://10.0.2.2/profile/image/";
                image.add(img + jsonobject.getString("pp_image"));
                user_name=jsonobject.getString("pp_username");
                departmenta=jsonobject.getString("pp_department");
                email_id=jsonobject.getString("pp_email");
                phone=jsonobject.getString("pp_phone");
                DEsgination=jsonobject.getString("pp_designation");
                Addresss=jsonobject.getString("pp_address");



            }
        } catch (Exception e) {
        }

        return null;
    }
    @Override
    protected void onPostExecute(Void args ) {
        image123.setImageBitmap(Bitmap.bitmap);
        username.setText(user_name.toString());
        department.setText(departmenta.toString());
        email.setText(email_id.toString());
        mobile.setText(phone.toString());
        designation.setText(Addresss.toString());
        address.setText(Addresss.toString());
         }
      }

I tried this way but not getting the Image in the ImageView.

Upvotes: 0

Views: 901

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006964

Given a URL, you can load the image into an ImageView using an image-loading library, such as Picasso.

In your case, you have N images and, as far as I can tell, you have just one ImageView. It will be up to you to decide which of your N images is the one that you want to load into that ImageView.

Upvotes: 1

Related Questions