本文介绍了从片段中的响应中获取后,寻呼机适配器不显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从响应中得到三张图像,然后我将其存储在数组列表中,然后我尝试在 PagerAdapter 中进行设置,但在我的视图寻呼机中没有显示任何内容,接下来是我的 pageradapter 类,谁能告诉我我犯了什么错误?
I am getting three images from response,and i am storing in arraylist,then i try to set in PagerAdapter,but nothing display in my view pager,following is my pageradapter class,can any one tell that what is mistake i made?
我正在使用片段
在我的 Postexecute 中,我将它设置在这样的视图寻呼机中
In my Postexecute i am setting it in view pager like this
adapter = new ImageAdapter(All_Product_Details.this.getActivity());
viewPager.setAdapter(adapter);
}
下面是我在 asynctask 之后设置的适配器
below is my adapter which i set after asynctask
public class ImageAdapter extends FragmentPagerAdapter {
Context context;
ImageAdapter(Context context)
{
this.context=context;
}
@Override
public int getCount() {
return multimglist.size();
}
@Override
public Fragment getItem(int i) {
return null;
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.activity_horizontal_margin);
imageView.setPadding(padding, padding, padding, padding);
//imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
Picasso.with(context).load(multimglist.get(position)).into(imageView);
// imageView.setImageURI(Uri.parse(imgStr[position]));
((ViewPager) container).addView(imageView, 0);
return imageView;
}
}
推荐答案
this is my pager adapter change according that
public class LoginViewPagerCA extends PagerAdapter {
SparseArray<View> views = new SparseArray<>();
List<Viewpager_POJO> listofPersons;
LayoutInflater inflater;
Context context;
private int count = 4;
public LoginViewPagerCA(Context context, List<Viewpager_POJO> listofPersons) {
this.context = context;
this.listofPersons = listofPersons;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return listofPersons.size();
}
public void setCount(int count) {
this.count = count;
}
@Override
public boolean isViewFromObject(View view, Object obj) {
// TODO Auto-generated method stub
return view == ((LinearLayout) obj);
}
public void setData(ArrayList<Viewpager_POJO> data) {
listofPersons = data;
}
public Object instantiateItem(ViewGroup container, final int position)
{
final TextView txtFstName, txtLstName, txtRollno, txtArrTime, txtTimeLeft;
ImageView imgView;
final Viewpager_POJO rowperson = listofPersons.get(position);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View itemView = inflater.inflate(R.layout.landing_pager_item, container, false);
txtFstName = (TextView) itemView.findViewById(R.id.pager_big_tv);
txtLstName = (TextView) itemView.findViewById(R.id.pager_small_tv);
imgView = (ImageView) itemView.findViewById(R.id.pager_image);
try {
// txtCompn.setText((position + 1) + "/" + StuFirstNM.length);
txtFstName.setText(rowperson.getDesc());
txtLstName.setText(rowperson.getRating());
//new LoadImage(imgView).execute(rowperson.getUrls());
if (!TextUtils.isEmpty(rowperson.getUrls())) {
// PicassoTrustAll.getInstance(context).load(rowperson.getUrls()).placeholder(context.getResources().getDr`enter code here`awable(R.drawable.ic_launcher)).error(context.getResources().getDrawable(R.drawable.ic_launcher)).into(imgView);
//
byte[] imgbytes = Base64.decode(rowperson.getStrImm(), Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(imgbytes, 0, imgbytes.length);
imgView.setImageBitmap(bitmap);
// PicassoTrustAll.getInstance(context)
// .load(rowperson.getUrls())
// .error(R.mipmap.landinglogo)
// .into(imgView);
Log.w("Testing", "Image Download URL=" + rowperson.getUrls());
} else {
imgView.setBackgroundResource(R.mipmap.landinglogo);
}
((ViewPager) container).addView(itemView);
views.put(position, itemView);
} catch (Exception e)
{
e.printStackTrace();
}
return itemView;
}
public void destroyItem(ViewGroup container, int position, Object object) {
View view = (View) object;
((ViewPager) container).removeView(view);
views.remove(position);
view = null;
}
这篇关于从片段中的响应中获取后,寻呼机适配器不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!