Home > Mobile >  Custom inheritance PagerAdapter subclass PictureAdapter adapter created how did not perform?
Custom inheritance PagerAdapter subclass PictureAdapter adapter created how did not perform?

Time:09-27

Custom inheritance PagerAdapter subclass PictureAdapter adapter created when new PictureAdapter () does not execute the code inside, this is how to return a responsibility, seek advice, mainly as follows:
 package com. Example. Googleplay. Holder; 

import java.util.List;

The import com. Example. Googleplay. R;
The import com. Example. Googleplay. Base. BaseHolder;
The import com. Example. Googleplay. Conf. The URLS.
The import com. Example. Googleplay. Utils. BitmapHelper;
The import com. Example. Googleplay. Utils. LogUtils;
The import com. Example. Googleplay. Utils. UIUtils;
The import com. Lidroid. Xutils. ViewUtils;
The import com. Lidroid. Xutils. View. The annotation. ViewInject;

The import android. Support. The v4. View. PagerAdapter;
The import android. Support. The v4. View. ViewPager;
The import android. View. The view;
The import android. View. ViewGroup;
The import android. Widget. ImageView;
The import android. Widget. ImageView. ScaleType;
The import android. Widget. LinearLayout;

Public class PictureHolder extends BaseHolder
{

@ ViewInject (R.i d.i tem_home_picture_pager)
ViewPager mViewPager;

@ ViewInject (R.i d.i tem_home_picture_container_indicator)
LinearLayout mContainerIndicator;

Public List MDatas;

@ Override
Public View initHolderView ()
{
View the View=the inflate (UIUtils getContext (), R.l ayout. Item_home_picture, null);
//injection
ViewUtils. Inject (this view);

Return the view;
}

@ Override
Public void refreshHolderView (List Datas)
{
MDatas=datas;
PictureAdapter adapter=new PictureAdapter ();
MViewPager. SetAdapter (adapter);
}

The class PictureAdapter extends PagerAdapter
{
@ Override
Public int getCount ()
{
If (mDatas!=null)
{
Return mDatas. The size ();
}
return 0;
}

@ Override
Public Boolean isViewFromObject (View View, Object Object)
{
Return the view==object;
}

@ Override
Public Object instantiateItem (ViewGroup container, int position)
{
ImageView iv=new ImageView (UIUtils getContext ());

Iv. SetScaleType (ScaleType. FIT_XY);

Iv. SetImageResource (R.d rawable. Ic_default);

//get photo full path
String uri=URLS. IMAGEBASEURL + mDatas. Get (position);
BitmapHelper. The display (iv, uri);

Container. AddView (iv);

LogUtils. Sf (" instantiateItem - & gt; Container. AddView (iv) ");

Return the iv;
}

@ Override
Public void destroyItem (ViewGroup container, int the position, the Object Object)
{
Container. RemoveView ((View) object);
}
}
}

CodePudding user response:

Found the problem, not perform mDatas descendants adapter is because the data is empty, cause not perform PictureAdapter directly

CodePudding user response:

ViewPager to recommend an article to realize image automatically infinite wheel, the realization of the cool effect (showed multiple item) at the same time, the navigation bar at the bottom of the middle https://blog.csdn.net/jason_rui/article/details/102501079
  • Related