Way1:
//MainActivity.java
public class MainActivity  {
private static String IMG_URL = "http://openweathermap.org/img/w/";
String imgicon;
// any inside Method / Oncreate
{
//image recived by downloadnew DownloadImageTask((ImageView) findViewById(R.id.imgIcon)) .execute(IMG_URL + imgicon + ".png");}}//endof Oncleate method//start//outside from method or outside from OnCreate
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); } }
//end DownloadImageTask
} //end of MainActivity
Way 2:
inside retrofit
//outside from retrofit method
String imgicon;//inside in retrofit method//start retrofittry { IPLocData = response.body();
imgicon = IPLocData.getWeather().get(0).getIcon();
//Imagefetch by runon thread getCurrentWeather()Thread thread = new Thread(new Runnable() { @Override public void run() { try { // https://erikflowers.github.io/weather-icons/ //imgicon recived value from api dataWay 3:ImageLoadEfftectActivity.javaactivity_image_load_efftect.xml<ImageViewandroid:scaleType="fitXY"android:id="@+id/imgIcon2"android:layout_width="wrap_content"android:layout_height="wrap_content" />
 
Comments
Post a Comment