android - universal image loader not working for Relative layout in ArrayAdapter -
i have list of image path's in json response. prompt set images background of relative layout path. on have been advised , used arrayadapter , universal image loader achieve this.i hope myself 95% have done this. problem loaded 1 image in ui 2 images have in json response.
here tried in arrayadapter class inside getview() method
relativelayout laycontentoflistview; // initialize relative layout container laycontentoflistview = (relativelayout)rowview.findviewbyid(r.id.laycontentoflistview); // load image, decode bitmap , return bitmap callback imagesize targetsize = new imagesize(150, 100); // result bitmap fit size imageloader.loadimage(fullimagepath, targetsize, new simpleimageloadinglistener() { @override public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) { if (loadedimage != null) { drawable d = new bitmapdrawable(context.getresources(), loadedimage); laycontentoflistview.setbackgrounddrawable(d); } } });
this relative layout content in list view of each row.
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/laycontentoflistview" android:paddingleft="10dp" android:paddingright="10dp" android:paddingbottom="10dp" android:orientation="vertical" android:background="@drawable/gray_boardered_transparent_shape" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/color_red" android:paddingtop="5dp" android:paddingbottom="5dp" android:paddingleft="10dp" android:paddingright="10dp" android:id="@+id/layheader" android:layout_marginbottom="10dp" android:orientation="vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/lblmerchantname" android:layout_weight="1" android:text="merchant name" android:textalignment="textstart" android:textsize="15sp" android:textcolor="@color/color_white" /> </linearlayout> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="40dp" android:id="@+id/lblrewardpoints" android:text="reward points" android:textsize="15sp" android:textcolor="@color/color_white" android:gravity="center" android:layout_centerhorizontal="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginbottom="20dp" android:id="@+id/lblrewardname" android:text="reward name" android:textsize="15sp" android:textcolor="@color/color_white" android:layout_below="@+id/lblrewardpoints" android:layout_centerhorizontal="true" /> <imageview android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imgmemstar" android:src="@drawable/icon_mem_star" android:layout_below="@+id/lblrewardname"/> <imageview android:layout_width="30dp" android:layout_height="30dp" android:layout_marginright="40dp" android:id="@+id/imgmemhand" android:src="@drawable/icon_mem_like" android:layout_below="@+id/lblrewardname" android:layout_toleftof="@+id/imgmemphone" /> <imageview android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imgmemphone" android:src="@drawable/icon_mem_phone" android:layout_below="@+id/lblrewardname" android:layout_centerhorizontal="true"/> <imageview android:layout_width="30dp" android:layout_height="30dp" android:layout_marginleft="40dp" android:id="@+id/imgmemqrcode" android:src="@drawable/icon_mem_qr" android:layout_below="@+id/lblrewardname" android:layout_torightof="@+id/imgmemphone" /> <imageview android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imgmemlocation" android:src="@drawable/icon_mem_location" android:layout_below="@+id/lblrewardname" android:layout_alignparentright="true"/> </relativelayout>
and output screen
i can't found solution long. can please charity on this.thanks.!
i have tested , working fine.
import android.graphics.bitmap; import android.graphics.drawable.bitmapdrawable; import android.graphics.drawable.drawable; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.widget.relativelayout; import com.squareup.picasso.picasso; import com.squareup.picasso.target; public class mainactivity extends appcompatactivity { relativelayout relativelayout; string url = "image_url"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); relativelayout = (relativelayout) findviewbyid(r.id.lay); picasso.with(this) .load(url) .into(new target() { @override public void onbitmaploaded (final bitmap bitmap, picasso.loadedfrom from){ /* save bitmap or here */ //set in imageview drawable dr = new bitmapdrawable(bitmap); relativelayout.setbackground(dr); } @override public void onprepareload(drawable placeholderdrawable) { } @override public void onbitmapfailed(drawable errordrawable) { } }); } }
use in manifest before application.
<uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.internet" />
add following line in dependencies or gradle.
compile 'com.squareup.picasso:picasso:2.5.2'
Comments
Post a Comment