Awesome
Android AutoNotifyViewPager
This project is an upgraded version of ViewPager. AutoNotifies your adapter when data get's changed.
##Prerequisites
Why?
- By default ViewPager's
adapter
should be notified using <kbd>mAdapter.notifyDataSetChanged()</kbd> if data get's changed after setting adapter to avoid IllegalStateException - It get's difficult to update your adapter when
PagerAdapter
is in other class, typically different <kbd>*.java</kbd> - <u>Example</u> :
- In this app,
ListView's adapter
&ViewPager's adapter
share's same content. - When scrolled down to bottom of the page in ListView,
GetMoreData
is triggered, fetched, parsed & updated to ListView's adapter. - Seems easy, but when the user clicks & navigates to
ViewPager
after triggered and before updated, you end up inIllegalStateException
as the data got changed but not notified. - This can be avoided having complex
eventListeners
, instead simply use AutoNotifyViewPager
- In this app,
When?
- Notifies your
adapter
<u>when view get's changed</u>
Not When!
adapter
get's content.
Usage
Import any one *.jar into /libs
In layout.xml
<com.venomvendor.library.AutoNotifyViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Instead of <s>ViewPager mPager
</s> use <kbd>AutoNotifyViewPager mPager</kbd>
AutoNotifyViewPager mPager = (AutoNotifyViewPager) findViewById(R.id.pager);
mPager.setAdapter(adapter);
imports
import com.venomvendor.library.AutoNotifyViewPager.*;
<u>imports not to have</u>
import android.support.v4.view.ViewPager.*
ProGuard
-dontwarn com.venomvendor.library.AutoNotifyViewPager.**
-keep public class com.venomvendor.library.AutoNotifyViewPager.** { *; }
Author : VenomVendor
#License Copyright (C) 2015 VenomVendor info@VenomVendor.com Copyright (C) 2011 The Android Open Source Project.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.