android


How to pass image as url into arraylist using picaso library instead of drawable resource?


arr_title,arr_description,arr_img are the array list
arr_title.add(title);
arr_description.add(description);
arr_img.add(R.drawable.ic_launcher);
arr_img , here takes a static image which is working fine . But , how to get it done dynamically from an image url , so that I get to fetch image from url and pass it into this arr_img , than just drawable image .
I tried , using Picaso library , but I did not understand , how to use it in place of drawable ?
This is my ArrayAdapter
class MyClass extends ArrayAdapter
{
public MyClass(Context context, int resource, ArrayList img,ArrayList txt,ArrayList img_res)
{
super(context, resource,img);
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inf=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
convertView=inf.inflate(R.layout.post_list_design,null);
t1=(TextView)convertView.findViewById(R.id.title_list_design);
t1.setText(arr_title.get(position).toString());
t2=(TextView)convertView.findViewById(R.id.desc_list_design);
t2.setText(arr_description.get(position).toString());
i3=(ImageView)convertView.findViewById(R.id.img_logo);
i3.setImageResource((Integer)arr_img.get(position));
return convertView;
}
}
Try this, Its better store image URL in one String and pass the string in Load methods instead of direct passing URL. It works. For me it is working Great.
final ImageView image = (ImageView) view.findViewById(R.id.imageView1);
Picasso.with(getApplicationContext()).load("Image Url").into(image);
Picasso.with(context)
.load(arr_img.get(position))
.resize(100, 100)
.centerCrop()
.into(i3);
Try this!
Here is how you can do it, Lets suppose this is url list
static final String BASE = "http://i.imgur.com/";
static final String EXT = ".jpg";
static final String[] URLS = {
BASE + "CqmBjo5" + EXT, BASE + "zkaAooq" + EXT, BASE + "0gqnEaY" + EXT,
BASE + "9gbQ7YR" + EXT, BASE + "aFhEEby" + EXT, BASE + "0E2tgV7" + EXT,
BASE + "P5JLfjk" + EXT, BASE + "nz67a4F" + EXT, BASE + "dFH34N5" + EXT,
BASE + "FI49ftb" + EXT, BASE + "DvpvklR" + EXT, BASE + "DNKnbG8" + EXT,
BASE + "yAdbrLp" + EXT, BASE + "55w5Km7" + EXT, BASE + "NIwNTMR" + EXT,
BASE + "DAl0KB8" + EXT, BASE + "xZLIYFV" + EXT, BASE + "HvTyeh3" + EXT,
BASE + "Ig9oHCM" + EXT, BASE + "7GUv9qa" + EXT, BASE + "i5vXmXp" + EXT,
BASE + "glyvuXg" + EXT, BASE + "u6JF6JZ" + EXT, BASE + "ExwR7ap" + EXT,
BASE + "Q54zMKT" + EXT, BASE + "9t6hLbm" + EXT, BASE + "F8n3Ic6" + EXT,
BASE + "P5ZRSvT" + EXT, BASE + "jbemFzr" + EXT, BASE + "8B7haIK" + EXT,
BASE + "aSeTYQr" + EXT, BASE + "OKvWoTh" + EXT, BASE + "zD3gT4Z" + EXT,
BASE + "z77CaIt" + EXT,
};
and in your adapter
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inf=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
convertView=inf.inflate(R.layout.post_list_design,null);
t1=(TextView)convertView.findViewById(R.id.title_list_design);
t1.setText(arr_title.get(position).toString());
t2=(TextView)convertView.findViewById(R.id.desc_list_design);
t2.setText(arr_description.get(position).toString());
// Get the image URL for the current position.
String url = getItem(position);
i3=(ImageView)convertView.findViewById(R.id.img_logo);
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.fit()
.tag(context)
.into(i3);
return convertView;
}
}
This is pretty basic example of course you would have to pass the List of images to your adapter first.
Hope it helps
you can check here the detailed example
better to use getter setter method in array list.
then image is set as a string.
and in adapter to load every URL into imageview like...
Picasso.with(mFragment.getActivity()).load(mCardList.get(i).getProfilePictureFiles().get(0).getUrl()).into(image).placeholder(R.drawable.ic_launcher);

Related Links

Flutter build with C/C++ code - example?
Custom Socket in AppRTC Android
Could not find any version that matches com.theartofdev.edmodo:android-image-cropper:+
How to use handle multiple fragment to use method
Check Box Style based on Theme
Complex RealmObject: RealmObject with other RealmObject inside
getResource returns boolean instead String[]
Android: Container XML Layout wrap weight and fill height
Busy Indicator in react native
Facebook Analytics In-app notifications not showing push opens
How to adjust the volume of two media players simultaneously?
2 Views side by side with the same height
How to keep http requests pending until restoration of internet connectivity in Android Apps?
Actionbar ShowAsAction always not work with spinner dropdown
Application class does not run when app start?
Trouble adding Logout Button to Tab Fragment Class?

Categories

HOME
shell
notepad++
eslint
fpga
sh
vscode-extensions
dojo
regular-language
elasticsearch-5
rcloud
sendgrid-api-v3
heap
text-mining
watson-conversation
x-cart
capistrano3
event-sourcing
sencha-touch
sar
spring-async
event-store
exploit
gpio
shared
jackson-modules
jasmine-node
intersystems-cache
genexus-sd
quantlib
failover
sqsh
mockjax
sql-server-2000
autolisp
hreflang
login-script
keras-layer
hunspell
nested-lists
batching
tex
diacritics
p4merge
signals-slots
jboss-4.2.x
gitlist
mschart
geotiff
wpas
er-diagram
janus
structuremap4
adafruit
clipboard.js
swizzling
google-query-language
stream-processing
nio2
design-principles
concept-insights
rewrite
ess
django-urls
ons-api
sony-lifelog-api
mod-proxy
atoi
haskell-warp
dronekit-android
mraid
kubuntu
fits
code-documentation
post-commit-hook
formview
xml-namespaces
git-repo
getopt
openargs
kogrid
epiceditor
tree-balancing
panda3d
window-decoration
azman
apache-commons-dbutils
ikimagebrowserview
winmain
update-statement
strsep
django-paypal
cac
delimited-text
sun
technical-debt
xslcompiledtransform

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App