我正在使用此ArrayAdapter类在Listview中显示图像。但它几乎不显示1或2个图像,并且可以快速工作并显示图像。此外,当我向上滚动它然后图像消失。
@SuppressLint("ViewHolder")
public class New_Contest_ArrayAdapter extends ArrayAdapter<String>
{
private final Context context;
private final String[] contest_names;
private final String[] contest_start_dates;
private final String[] contest_end_dates;
private final String[] contest_pic_path;
int selected_pos=0;
public New_Contest_ArrayAdapter(Context context, int pos,String[] values,String[] values1,String[]values2,String[]pic_path)
{
super(context, pos, values);
this.context = context;
this.contest_names = values;
this.selected_pos=pos;
this.contest_start_dates=values1;
this.contest_end_dates=values2;
this.contest_pic_path=pic_path;
}
static class ViewHolder
{
public ImageView imgvw;
public TextView namesTV,datesTV,livestatusTV;
Button viewBTN,deleteBTN;
}
@SuppressWarnings("unused")
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
View rowView = null ;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (rowView == null)
{
holder = new ViewHolder();
// rowView = inflater.inflate(R.layout.new_contest_adapter,null);
rowView = inflater.inflate(R.layout.new_contest_adapter, parent, false);
holder.namesTV = (TextView) rowView.findViewById(R.id.textView1);
holder.datesTV = (TextView) rowView.findViewById(R.id.textView2);
holder.livestatusTV = (TextView) rowView.findViewById(R.id.imageView2);
holder.imgvw=(ImageView)rowView.findViewById(R.id.imageView1);
rowView.setTag(holder);
}
else
{
holder = (ViewHolder) rowView.getTag();
}
holder.namesTV.setText(""+contest_names[position]);
holder.datesTV.setText("Started On: "+contest_start_dates[position]);
holder.livestatusTV.setText("End On: "+contest_end_dates[position]);
if(contest_pic_path[position].length()>5)
{
setImagesUsingPicasso(contest_pic_path[position],holder.imgvw);
// Picasso.with(context).load(contest_pic_path[position]).fit().centerCrop().into(imgvw);
}
else
holder.imgvw.setImageResource(R.drawable.contest_icon);
return rowView;
}
//(((((( Loading Profile Pic with PICASSO Library ))))))))
private void setImagesUsingPicasso(String imagePath,final ImageView profileIV)
{
String url="http://pir.alphasols.com/VotingAppFolder/ContestProfilePicFolder/"+imagePath;
// Toast.makeText(getContext(), ""+url, Toast.LENGTH_LONG).show();
Log.e("url- ",""+url);
Picasso.with(context).load(url).into(new Target()
{
public void onBitmapLoaded ( Bitmap bitmap, Picasso.LoadedFrom from)
{
// theView.setImageBitmap(bitmap);
//bitmap=getRoundedRectBitmap(bitmap, 100);
profileIV.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable arg0)
{
}
@Override
public void onPrepareLoad(Drawable arg0) {
// TODO Auto-generated method stub
}
});
}
//((( Make Round Cirle IMAGEVIEW ))))
public static Bitmap getRoundedRectBitmap(Bitmap bitmap, int radius)
{
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(finalBitmap.getWidth() / 2 + 0.7f,
finalBitmap.getHeight() / 2 + 0.7f,
finalBitmap.getWidth() / 2 + 0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
} //EOF Class
答案 0 :(得分:0)
(更简单)呼叫Picasso.with(context).load(url).into(profileIV);
是否有效?你确定网址是否正确?
BTW:View rowView = null ;
我应该是View rowView = convertView ;
,您可以在if语句中移动getSystemService()
调用。