Display default image and replace that image with the uploaded image in android -
i want upload image particular id in server app , display getting toast message "uploaded".if there no image exists particular id want display default image , later want replace uploaded image.how can this?
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_student_details); { string image_url = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name; new downloadimagetask((imageview) findviewbyid(r.id.profilepiciv)) .execute(image_url); } public void onresume() { // after pause or @ startup super.onresume(); getintent(); string auid_num = auid_s.gettext().tostring(); string imei_num = imei_s.gettext().tostring(); string img_name = getintent().getstringextra("img_name"); string img_path = getintent().getstringextra("img_path"); //refresh stuff here senddatatoserver(auid_num, imei_num); string image_url = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name; new downloadimagetask((imageview) findviewbyid(r.id.profilepiciv)) .execute(image_url); } private class downloadimagetask extends asynctask<string, void, bitmap> { imageview bmimage; public downloadimagetask(imageview bmimage) { this.bmimage = bmimage; } protected bitmap doinbackground(string... urls) { string urldisplay = urls[0]; bitmap micon11 = null; try { inputstream in = new java.net.url(urldisplay).openstream(); micon11 = bitmapfactory.decodestream(in); } catch (exception e) { log.e("error", e.getmessage()); e.printstacktrace(); } return micon11; } protected void onpostexecute(bitmap result) { bmimage.setimagebitmap(result); } } xml: <imageview android:id="@+id/profilepiciv" android:layout_width="120dp" android:layout_height="120dp" android:background="@drawable/default_image" android:scaletype="fitxy" />
just use picasso library show image , use code download it. add in build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
and use
picasso.with(context).load(uri).error(r.drawable.default_image).into(imageview);
Comments
Post a Comment