From 6766cec00e3979435e1215ffccd43a48b6ac14db Mon Sep 17 00:00:00 2001 From: fccaikai <714564390@qq.com> Date: Sun, 23 Oct 2016 22:47:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96BaseAdapter=202.=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=B00.5.0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kcode/autoviewpager/MainActivity.java | 8 +++++++ .../view/AutoScrollViewPager.java | 6 +++++ .../view/AutoViewPager.java | 3 +++ .../view/BaseViewPagerAdapter.java | 23 +++++++++---------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/kcode/autoviewpager/MainActivity.java b/app/src/main/java/com/kcode/autoviewpager/MainActivity.java index fcfbe62..270b225 100644 --- a/app/src/main/java/com/kcode/autoviewpager/MainActivity.java +++ b/app/src/main/java/com/kcode/autoviewpager/MainActivity.java @@ -2,6 +2,7 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.widget.ImageView; import android.widget.Toast; import com.kcode.autoscrollviewpager.view.AutoScrollViewPager; @@ -33,6 +34,13 @@ protected void onCreate(Bundle savedInstanceState) { mViewPager = autoScrollViewPager.getViewPager(); mAdapter = new PictureViewPagerAdapter(getApplicationContext(),initData(),mViewPager, listener); + new BaseViewPagerAdapter(getApplicationContext(),initData(),mViewPager, listener){ + + @Override + public void loadImage(ImageView view, int position, Picture picture) { + + } + }; } private List initData() { diff --git a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoScrollViewPager.java b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoScrollViewPager.java index 345500d..725139b 100644 --- a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoScrollViewPager.java +++ b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoScrollViewPager.java @@ -40,6 +40,12 @@ private void init(Context context){ addView(mViewPager); } + public void setAdapter(BaseViewPagerAdapter adapter){ + if (mViewPager != null) { + mViewPager.init(mViewPager,adapter); + } + } + public AutoViewPager getViewPager() { return mViewPager; } diff --git a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoViewPager.java b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoViewPager.java index f4e9ef6..d7cceeb 100644 --- a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoViewPager.java +++ b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/AutoViewPager.java @@ -31,6 +31,9 @@ public AutoViewPager(Context context, AttributeSet attrs) { super(context, attrs); } + public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){ + adapter.init(viewPager,adapter); + } public void start(){ if (mTimer == null) { diff --git a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/BaseViewPagerAdapter.java b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/BaseViewPagerAdapter.java index b94207d..b2727cf 100644 --- a/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/BaseViewPagerAdapter.java +++ b/autoScrollViewPager/src/main/java/com/kcode/autoscrollviewpager/view/BaseViewPagerAdapter.java @@ -30,31 +30,30 @@ public BaseViewPagerAdapter(List t) { this.data = t; } - public BaseViewPagerAdapter(Context context, AutoViewPager viewPager) { + public BaseViewPagerAdapter(Context context) { this.mContext = context; - mView = viewPager; - mView.setAdapter(this); - mView.addOnPageChangeListener(this); - mView.setCurrentItem(0); } - public BaseViewPagerAdapter(Context context, AutoViewPager viewPager,OnAutoViewPagerItemClickListener listener) { + public BaseViewPagerAdapter(Context context, OnAutoViewPagerItemClickListener listener) { this.mContext = context; - mView = viewPager; this.listener = listener; - mView.setAdapter(this); - mView.addOnPageChangeListener(this); - mView.setCurrentItem(0); } - public BaseViewPagerAdapter(Context context, List data,AutoViewPager viewPager,OnAutoViewPagerItemClickListener listener) { + public BaseViewPagerAdapter(Context context, List data,OnAutoViewPagerItemClickListener listener) { this.mContext = context; - mView = viewPager; this.data = data; this.listener = listener; + } + + public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){ + mView = viewPager; mView.setAdapter(this); mView.addOnPageChangeListener(this); + + if (data == null || data.size() == 0){ + return; + } mView.setCurrentItem(0); mView.start();