0

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.

  • `image.add(img + jsonobject.getString("pp_image"));` -- what is `image`? Where is it declared? Why do you call `add()` on it N times, for each pass of your loop? `image123.setImageBitmap(Bitmap.bitmap)` -- what is `Bitmap.bitmap`? What does `Bitmap.bitmap` have to do with `image`? Why do you post source code to a question that does not compile (you are missing a semicolon)? – CommonsWare Dec 17 '16 at 14:08
  • ArrayList image=new ArrayList(); –  Dec 17 '16 at 14:10
  • and i am just trying from some tutorials that's why there's some mix code sry for that –  Dec 17 '16 at 14:12
  • How are you using `image`, then, after you have called `add()` N times to add N URLs to it? You do not have any code to use `image` in your question. – CommonsWare Dec 17 '16 at 14:14
  • i don't know how to set image... i just tried this way... i know there's no sense for it but m new in this.. –  Dec 17 '16 at 14:16
  • Try looking at this http://stackoverflow.com/questions/2471935/how-to-load-an-imageview-by-url-in-android – Melchizedek Dec 17 '16 at 14:19
  • You have `N` images urls in your image `ArrayList`. Are you planning to show all images in a single `ImageView`? – K Neeraj Lal Dec 17 '16 at 14:27

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491