Android ListFragment中有很多大位图的毕加索
我有一个关于毕加索图书馆的问题。我使用ListFragment中的ListView从服务器下载图像。我正在使用BaseAdapter填充该ListView。问题是,当我看到大量图像(10+)时,当毕加索试图加载它们时,我遇到了加载问题。基本上,我必须在它们加载之前等待一段时间,突然它们都同时加载。只有当我转到另一个活动并返回带有此片段的MainActivity时,才会发生这种情况这是我的baseAdapter源代码:Android ListFragment中有很多大位图的毕加索,android,android-listview,bitmap,android-listfragment,picasso,Android,Android Listview,Bitmap,Android Listfragment,Picasso,我有一个关于毕加索图书馆的问题。我使用ListFragment中的ListView从服务器下载图像。我正在使用BaseAdapter填充该ListView。问题是,当我看到大量图像(10+)时,当毕加索试图加载它们时,我遇到了加载问题。基本上,我必须在它们加载之前等待一段时间,突然它们都同时加载。只有当我转到另一个活动并返回带有此片段的MainActivity时,才会发生这种情况这是我的baseAdapter源代码: public class MySimpleArrayAdapter exten
public class MySimpleArrayAdapter extends BaseAdapter {
private final Context context;
private final ArrayList<String> values;
private final double[] lat2;
private final double[] lon2;
private final double lat;
private final double lon;
private final int[] id;
private final int[] timestamp;
private final int[] likes;
private final String[] tags;
private final String[] statusText;
private final String[] imgLink;
private final String[] author;
public MySimpleArrayAdapter(Context context, ArrayList<String> values, double[] lat2,double[] lon2,double lat, double lon, int[] id,int[] timestamp,int[] likes, String[] tags,String[] statusText,String[] imgLink, String[] author) {
this.context = context;
this.values = values;
this.lat2 = lat2;
this.lon2 = lon2;
this.lat = lat;
this.lon = lon;
this.id = id;
this.timestamp = timestamp;
this.likes = likes;
this.tags = tags;
this.statusText = statusText;
this.imgLink = imgLink;
this.author = author;
}
@Override
public int getCount() {
if(lat2!=null){
return lat2.length;}
else{
return 0;
}
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.simple_list_item, parent, false);
}
try {
int distance = 0;
if (lat2 != null && lon2 != null) {
distance = (int) computeDistanceBetween(new LatLng(lat, lon), new LatLng(lat2[getCount()-position-1], lon2[getCount()-position-1]));
}
ImageButton like = (ImageButton)v.findViewById(R.id.likeButton);
like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
likeStatus(id[getCount()-position-1],author[getCount()-position-1]);
}
});
TextView firsteLine = (TextView) v.findViewById(R.id.StatusText);
ImageView imageView = (ImageView) v.findViewById(R.id.StatusImage);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String author1 = null;
String link = null;
String text3 = null;
String tags1 = null;
int distance = 0;
int ts = 0;
int id1 = 0;
int likes1 = 0;
LatLng ll = new LatLng(lat, lon);
id1 = id[getCount()-position-1];
likes1 = likes[getCount()-position-1];
author1 = author[getCount()-position-1];
link = imgLink[getCount()-position-1];
text3 = statusText[getCount()-position-1];
if (lat2 != null&&lon2 != null) {
distance = (int) computeDistanceBetween(ll, new LatLng(lat2[getCount()-position-1], lon2[getCount()-position-1]));
}
else {
distance=0;
}
ts = timestamp[getCount()-position-1];
tags1 = tags[getCount()-position-1];
Intent intent = new Intent(context, ShowMarkerContent.class);
intent.putExtra("id", id1);
intent.putExtra("likes", likes1);
intent.putExtra("tags", tags1);
intent.putExtra("link", link);
intent.putExtra("author", author1);
intent.putExtra("text", text3);
intent.putExtra("distance", distance);
intent.putExtra("time", ts);
intent.putExtra("number", getCount()-position-1);
context.startActivity(intent);
}
});
Picasso.with(context).cancelRequest(imageView);
Picasso.with(context).load("http://files.guri.sk/" + imgLink[getCount()-position-1]).fit().centerCrop().error(R.mipmap.ic_launcher).placeholder(R.drawable.progress_animation).into(imageView);
Log.d("Tag","http://files.guri.sk/"+imgLink[getCount()-position-1]);
if (distance > 1000) {
distance = distance / 1000;
firsteLine.setText(values.get(getCount()-position-1) + " (" + MySearchAdapter.caluculateTimeAgo(timestamp[getCount()-position-1]) + ", " + String.valueOf(distance) + "km) ");
} else {
firsteLine.setText(values.get(getCount()-position-1) + " (" + MySearchAdapter.caluculateTimeAgo(timestamp[getCount()-position-1]) + ", " + String.valueOf(distance) + "m) ");
}
}
catch (IndexOutOfBoundsException e){
}
return v;
}
public void likeStatus(int id, String user){
try {
JSONObject toSend = new JSONObject();
toSend.put("user", user);
toSend.put("id", id);
JSONTransmitterLike transmitter = new JSONTransmitterLike();
String resp = null;
try {
resp = transmitter.execute(new JSONObject[]{toSend}).get();
resp = resp.replace("\n", "").replace("\r", "");
Log.d("Tag", resp);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
JSONObject jObj = new JSONObject(resp);
int numberOfLikes = jObj.getInt("like_total");
int result = jObj.getInt("result");
int liked = jObj.getInt("liked");
if (result == 2) {
unLike(id, user);
} else {
Toast.makeText(context,"You like this",Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public void unLike(int id, String user) {
try {
JSONObject toSend = new JSONObject();
toSend.put("user", user);
toSend.put("id", id);
JSONTransmitterUnlike transmitter = new JSONTransmitterUnlike();
String resp = null;
try {
resp = transmitter.execute(new JSONObject[]{toSend}).get();
resp = resp.replace("\n", "").replace("\r", "");
Log.d("Tag", resp);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
JSONObject jObj = new JSONObject(resp);
int numberOfLikes = jObj.getInt("like_total");
int result = jObj.getInt("result");
int liked = jObj.getInt("liked");
Toast.makeText(context,"You don't like this",Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
公共类mySimpleArrayaAdapter扩展了BaseAdapter{
私人最终语境;
私有最终ArrayList值;
私人最终双[]lat2;
二等兵;
私人最终双lat;
二等兵;
私有最终int[]id;
私有最终int[]时间戳;
个人爱好;
私有最终字符串[]标记;
私有最终字符串[]状态文本;
私有最终字符串[]imgLink;
私有最终字符串[]作者;
public MySimpleArrayAdapter(上下文上下文、数组列表值、双[]lat2、双[]lon2、双lat、双lon、int[]id、int[]时间戳、int[]likes、String[]标记、String[]statusText、String[]imgLink、String[]author){
this.context=上下文;
这个值=值;
this.lat2=lat2;
this.lon2=lon2;
this.lat=lat;
this.lon=lon;
this.id=id;
this.timestamp=时间戳;
this.likes=喜欢;
this.tags=标签;
this.statusText=状态文本;
this.imgLink=imgLink;
this.author=作者;
}
@凌驾
public int getCount(){
如果(lat2!=null){
返回lat2.length;}
否则{
返回0;
}
}
@凌驾
公共对象getItem(int位置){
返回null;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
视图v=转换视图;
if(convertView==null){
LayoutInflater li=(LayoutInflater)上下文
.getSystemService(上下文布局\充气机\服务);
v=li.充气(R.布局.简单列表项,父项,false);
}
试一试{
整数距离=0;
if(lat2!=null&&lon2!=null){
距离=(int)计算出的距离介于(新板条(板条,经纬度),新板条(板条2[getCount()-position-1],经纬度2[getCount()-position-1])之间;
}
ImageButton like=(ImageButton)v.findViewById(R.id.likeButton);
like.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
likeStatus(id[getCount()-position-1],作者[getCount()-position-1]);
}
});
TextView第一行=(TextView)v.findViewById(R.id.StatusText);
ImageView ImageView=(ImageView)v.findViewById(R.id.StatusImage);
imageView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
字符串author1=null;
字符串链接=null;
字符串text3=null;
字符串tags1=null;
整数距离=0;
int ts=0;
int id1=0;
int likes1=0;
LatLng ll=新LatLng(lat,lon);
id1=id[getCount()-position-1];
likes1=likes[getCount()-position-1];
author1=author[getCount()-position-1];
link=imgLink[getCount()-position-1];
text3=statusText[getCount()-position-1];
if(lat2!=null&&lon2!=null){
距离=(int)计算的距离介于(ll,新LatLng(lat2[getCount()-position-1],lon2[getCount()-position-1])之间;
}
否则{
距离=0;
}
ts=时间戳[getCount()-position-1];
tags1=标记[getCount()-position-1];
意向意向=新意向(上下文,ShowMarkerContent.class);
意向。额外(“id”,id1);
意图。putExtra(“喜欢”,喜欢1);
意向。额外(“标签”,标签1);
意向。额外(“链接”,链接);
意图。putExtra(“作者”,author1);
意图。额外(“文本”,text3);
意向。额外(“距离”,距离);
意图。额外(“时间”,ts);
intent.putExtra(“number”,getCount()-position-1);
背景。开始触觉(意图);
}
});
毕加索.with(context).cancelRequest(imageView);
毕加索.with(context).load(“http://files.guri.sk/“+imgLink[getCount()-position-1]).fit().centerCrop().error(R.mipmap.ic_launcher).占位符(R.drawable.progress_animation).插入(imageView);
Log.d(“标记”http://files.guri.sk/“+imgLink[getCount()-position-1]);
如果(距离>1000){
距离=距离/1000;
firsteLine.setText(values.get(getCount()-position-1)+”(“+MySearchAdapter.caluculateTimeAgo(timestamp[getCount()-position-1])+”,“+String.valueOf(distance)+“km”);
}否则{
firsteLine.setText(values.get(getCount()-position-1)+”(“+MySearchAdapter.caluculateTimeAgo(timestamp[getCount()-position-1])+”,“+String.valueOf(distance)+“m”);
}
}
catch(IndexOutOfBoundsException e){
}
返回v;
}
公共void likeStatus(int-id,字符串用户){
试一试{
JSONObject toSend=新的JSONObject();
toSend.put(“用户”,user);
toSend.put(“id”,id);
JsonTransmiterLike变送器=新的JsonTransmiterLike();
字符串resp=null;
试一试{
resp=transmitter.execute(新的JSONObject[]{toSend}).get();
resp=resp.replace(“\n”和“)。replace(“\r”和“);
日志d(“标签”,分别);
}捕捉(中断异常e){
e、 printStackTrace();
}捕获(执行例外){
e、 printStackTrace();
}
JSONObject jObj=新JSONObject(resp);
int numberOfLikes=jObj.getInt(“like_total”);
int result=jObj.getInt(“结果”);
int liked=jObj.getInt(“liked”);