How to set image on image view in Android by MySQL database with the help of PHP file and Android AsyncTask? -


i have list view , want set values there control.i done problem image view, have 1 php file name show_image.php takes 1 parameter name id method , give image. how can use file take user image there id , show on imageview in android? can me out problem follows code are:

1> android asynctask method:-

 class loadallfrnz extends asynctask<string, string, string> {      /**      * before starting background thread show progress dialog      * */     private progressdialog progressdialog = new progressdialog(             getactivity());     inputstream inputstream = null;     string result = "";     string user_image_url[];      string imageurl;     drawable d;     //string user_id[];     arraylist<string> user_id = new arraylist<string>();      //this adds element list.      @override     protected void onpreexecute() {         super.onpreexecute();      }      /**      * creating product      * */     protected string doinbackground(string... args) {           //global declared url_all_frnzlist = "http://10.0.2.2:8080/application/frnzlist.php";           list<namevaluepair> params = new arraylist<namevaluepair>();         jsonobject json = jsonparser.makehttprequest(url_all_frnzlist,                 "post", params);           try {             success = json.getint(tag_success);              if (success == 1) {                 int j = 0;                 friend_json_array = json.getjsonarray("product");                  (int = 0; < friend_json_array.length(); i++) {                      jsonobject jo = friend_json_array.getjsonobject(i);                       user_id.add(jo.getstring("id"));                     string id = jo.getstring("id");                     string username = jo.getstring("user_name");                     string user_email = jo.getstring("e_mail");                      hashmap<string, string> map = new hashmap<string, string>();                      //map.put("id",  "http://10.0.2.2:8080/application/show_image.php?id="+id);                     map.put("username", username);                     map.put("user_email", user_email);                       hashmap<string, bitmap> map_image = new hashmap<string, bitmap>();                     string newurl ="http://10.0.2.2:8080/shiva/show_image.php?id="+id;                      bitmap bitmap = bitmapfactory.decodestream((inputstream)new url(newurl).getcontent());                     map_image.put("id", bitmap);                       frnzlist.add(map);                  }              } else {              }         } catch (jsonexception e) {             e.printstacktrace();         } catch (malformedurlexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          return null;     }      /**      * after completing background task dismiss progress dialog      * **/     protected void onpostexecute(string file_url) {          getactivity().runonuithread(new runnable() {              @override             public void run() {                  adapter = new simpleadapter(getactivity(), frnzlist,                         r.layout.list_friend, new string[] { "username",                          "user_email","id"}, new int[] { r.id.tv_fnd_db,                                 r.id.tv_fnd_name, r.id.img_fns_pic });                   setlistadapter(adapter);                 ((baseadapter) adapter).notifydatasetchanged();              }           });          (string innerlist : user_id) {             string url="http://10.0.2.2:8080/application/show_image.php?id=";             toast.maketext(getactivity(), url+innerlist, toast.length_long).show();            }       }  } 

2> show_image.php file run perfect providing id in browser . may no error in file

<?php                        require_once __dir__ . '/db_connect.php';                       $db = new db_connect();                       $id=$_get['id'];                     $sql = "select photo,phototype login_user id='$id'";                     // execute query                     $result = mysql_query($sql);                     // loop through each records                      if($result);                     {                      $row=mysql_fetch_array($result);                     $type="content-type: ".$row['phototype'];                     header($type);                     echo $row['photo'];                       }  ?> 

3> frnzlist.php file, not sure if change want in don't have error , gives proper output.

<?php  $response = array(); require_once __dir__ . '/db_connect.php'; $db = new db_connect(); $result = mysql_query("select * login_user") or die(mysql_error()); if (mysql_num_rows($result) > 0) {      $response["product"] = array();      while ($row = mysql_fetch_array($result)) {          $product = array();              $product["id"] = $row["id"];         $product["user_name"] = $row["user_name"];         $product["e_mail"] = $row["e_mail"];         array_push($response["product"], $product);     }     $response["success"] = 1;     echo json_encode($response);     exit(); } else {      $response["success"] = 0;     $response["message"] = "no user found";     echo json_encode($response);     exit(); } ?> 


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -