我需要说我对android很陌生。最近在我的回收站视图中,当我加载 100 多个项目(主要是图片)时,我的应用程序首先滞后,然后自行关闭而没有错误消息。这些是探查器值。我想知道的是这些值是否正常?如果不是什么是正常值。我想我需要提一下,这是像 facebook 这样的共享应用程序。
我的适配器代码:
if(list.get(position).getPost().getTogroup()!=null){
holder.groupname.setText(list.get(position).getPost().getTogroup());
holder.profilephoto.setVisibility(View.VISIBLE);
holder.namebelow.setVisibility(View.VISIBLE);
holder.groupname.setVisibility(View.VISIBLE);
holder.usernamebelow.setVisibility(View.VISIBLE);
Glide.with(holder.itemView.getContext()).load(list.get(position).getPost().getGroupppurl()).into(holder.profilephoto);
holder.namebelow.setText(list.get(position).getUser().getNamesurname());
holder.usernamebelow.setText("(@"+list.get(position).getUser().getUsername()+")");
if(list.get(position).getPost().getType().equals("text")){
if(!list.get(position).getPost().getDescription().equals("")){
holder.descrition.setText(list.get(position).getPost().getDescription());
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("link")){
holder.linkpreview.setVisibility(View.VISIBLE);
String url=list.get(position).getPost().getUrl();
String linkimageurl=list.get(position).getPost().getLinkimageurl();
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(linkimageurl).into(holder.linkimage);
}
String linktitle=list.get(position).getPost().getLinktitle();
holder.linktitle.setText(linktitle);
String linkdesc = list.get(position).getPost().getLinkdesc();
holder.linkdesc.setText(linkdesc);
holder.linkurl.setText(url);
String description = list.get(position).getPost().getDescription();
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("image")){
float iratio = list.get(position).getPost().getImageratio();
holder.imagelayout.setVisibility(View.VISIBLE);
holder.postimage.setRatio(iratio);
String url=list.get(position).getPost().getUrl();
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(url).addListener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
holder.imageloadingbar.setVisibility(View.INVISIBLE);
return false;
}
}).into(holder.postimage);
}
String description = list.get(position).getPost().getDescription();;
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("video")){
holder.videoplayerjz.widthRatio=1;
holder.videoplayerjz.heightRatio=1;
holder.videoplayerjz.fullscreenButton.setVisibility(View.GONE);
holder.videoplayerjz.setVisibility(View.VISIBLE);
String url=list.get(position).getPost().getThumburl();
holder.videoplayerjz.setUp(
list.get(position).getPost().getUrl(),
"", Jzvd.SCREEN_WINDOW_LIST);
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(url).into(holder.videoplayerjz.thumbImageView);
}
String description = list.get(position).getPost().getDescription();
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
}
if(list.get(position).getPost().getTogroup()==null){
holder.profilephoto.setVisibility(View.VISIBLE);
holder.namecenter.setVisibility(View.VISIBLE);
holder.usernamecenter.setVisibility(View.VISIBLE);
Glide.with(holder.itemView.getContext()).load(list.get(position).getUser().getProfilephotourl()).into(holder.profilephoto);
holder.namecenter.setText(list.get(position).getUser().getNamesurname());
holder.usernamecenter.setText("(@"+list.get(position).getUser().getUsername()+")");
if(list.get(position).getPost().getType().equals("text")){
if(!list.get(position).getPost().getDescription().equals("")){
holder.descrition.setText(list.get(position).getPost().getDescription());
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("link")){
holder.linkpreview.setVisibility(View.VISIBLE);
String url=list.get(position).getPost().getUrl();
String linkimageurl=list.get(position).getPost().getLinkimageurl();
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(linkimageurl).into(holder.linkimage);
}
String linktitle=list.get(position).getPost().getLinktitle();
holder.linktitle.setText(linktitle);
String linkdesc = list.get(position).getPost().getLinkdesc();
holder.linkdesc.setText(linkdesc);
holder.linkurl.setText(url);
String description = list.get(position).getPost().getDescription();
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("image")){
float iratio = list.get(position).getPost().getImageratio();
holder.imagelayout.setVisibility(View.VISIBLE);
holder.postimage.setRatio(iratio);
String url=list.get(position).getPost().getUrl();
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(url).addListener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
holder.imageloadingbar.setVisibility(View.INVISIBLE);
return false;
}
}).into(holder.postimage);
}
String description = list.get(position).getPost().getDescription();;
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
if(list.get(position).getPost().getType().equals("video")){
holder.videoplayerjz.widthRatio=1;
holder.videoplayerjz.heightRatio=1;
holder.videoplayerjz.fullscreenButton.setVisibility(View.GONE);
holder.videoplayerjz.setVisibility(View.VISIBLE);
String url=list.get(position).getPost().getThumburl();
holder.videoplayerjz.setUp(
list.get(position).getPost().getUrl(),
"", Jzvd.SCREEN_WINDOW_LIST);
if(holder.itemView.getContext()!=null){
Glide.with(holder.itemView.getContext()).load(url).into(holder.videoplayerjz.thumbImageView);
}
String description = list.get(position).getPost().getDescription();
if(!description.equals("")){
holder.descrition.setText(description);
holder.descrition.setVisibility(View.VISIBLE);
}
}
}