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

DialogFragment orientation change
android - showing listView in PreferenceActivity
how to do nested parsing using SAX Parser in android
How to load base64 string in webview?
Android - Spinner: text in several lines
Proguard Config File for Multi-Project Android App
Can't find NullPointerException in Android app
Overriding an OnSelectedItemListener in a Spinner
Call contacts by typing their name in textbox
Starting a new activity inside a thread
Android: How to detect Home button pressed with logs?
How to copy table fast from one database to another
MediaPlayer — maximum count and its influencing factors
synchronize blocks of data mobile client
Android : How get the current Application Context in AsyncTask?
Writing to a file based on contents of EditText

Categories

HOME
embedded
oracle12c
scikit-learn
hyperlink
awk
character-encoding
components
can
pyqt4
jetty
banner
frontend
spin
x-cart
intercom
qsqlquery
http-post
alpacajs
microsoft-dynamics-nav
xmonad
swagger-2.0
roslyn
visual-studio-extensions
direct3d11
jboss6.x
android-sharedpreferences
genexus-sd
testcomplete
database-comparison
android-sugarorm
pdw-file-browser
servicestack-text
hivemq
google-earth-engine
ods
demo
unordered-map
lpsolve
android-checkbox
apache-directory
flask-restful
textsum
hammer.js
trojan
static-cast
spring-data-couchbase
truezip
universal-analytics
cd-burning
testrail
grails-plugin
preprocessor
wso2developerstudio
expectations
refinerycms
clipboard.js
freepbx
lua-telegram-bot
php-socket
turbo-prolog
ascii-art
libvlc
state-restoration
concurrentmodification
qt5.2
oracle-spatial
forwarding
binomial-theorem
telepat
git-ftp
primitive-types
structuremap3
tweenlite
xml-namespaces
maven-scm
cfcache
gae-quotas
xmltodict
video-codecs
mantle
mysql-error-2013
virtual-pc
qtconcurrent
usertype
google-maps-mobile
filemerge
mtu
globals
blender-2.49
alsb
sifr3
appliance

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