-1
我正在使用此ArrayAdapter類在Listview中顯示圖像。但它幾乎不顯示1或2張圖像,並且可以快速工作並顯示圖像。另外,當我向上滾動它時,圖像會消失。在列表視圖中使用Picasso Library不顯示圖像ArrayAdapter
@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
讓我改變你的代碼,然後告訴你 –
Soory我改變了代碼,現在它正在混合所有圖片 –
請嘗試使用畢加索設置'R.drawable.contest_icon'。 –