The ViewPager doesn't scroll at al after refreshing the data

Akshay

I have an activity which has a coordinator layout with viewpager and CircularPager Indicator. I am trying to use MaterialRefreshLayout Library to do pull to refresh

The library can be found at Pull to refresh library

However, after I use pull to refresh my data, the viewpager just doesn't update the rest of the fragment and hence it dosn't scroll. Once I do background foreground it scrolls alright. Below is the Layout and activity

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/main_content"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context="myPackage.HomeActivity">

  <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

  </android.support.design.widget.AppBarLayout>

   <com.cjj.MaterialRefreshLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/refresh"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     app:overlay="true"
     app:progress_show_arrow="true"
     app:wave_show="false">

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="65dp"
        android:orientation="vertical">

         <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="@dimen/viewpager_height_none"
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <mypackage.ui.CirclePageIndicator
            android:id="@+id/indicator"
            style="@style/PageIndicator"
            android:clickable="false"
            app:fillColor="@color/default_circle_indicator_stroke_color"
            app:pageColor="@color/circlepageindicator_fill_color"
            app:radius="@dimen/circlepageindicator_radius" />

       </LinearLayout>
     </com.cjj.MaterialRefreshLayout>

   <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

 </android.support.design.widget.CoordinatorLayout>

And Below is the Activity

public class HomeActivity extends AppCompatActivity {


    private SectionPagerAdapter mSectionPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;
    private CirclePageIndicator mPagerCountIndicator;
    private MaterialRefreshLayout materialRefreshLayout;
    private Integer mTaskCount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_home);
        Bundle extras = getIntent().getExtras();
        if(extras != null) {
            mTaskCount= extras.getInt("task_Count");
        }
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

       updateandShowViewPager();

        materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id.refresh);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
            @Override
            public void onRefresh(MaterialRefreshLayout materialRefreshLayout) {
                refresh();
            }
        });
        materialRefreshLayout.finishRefresh();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_home, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB) // API 11
    private void startMyAsyncTask(AsyncTask asyncTask){
        //execute my AsyncTask and call Update and Show ViewPager
    }

   private void updateandShowViewPager(){
       AsyncTaskCallBack asyncTaskCallBack = new AsyncTaskCallBack() {
           @Override
           public void onSuccess() {

                   displayViewPager();
               }
           }
       };

       for(int taskCount  = 1; taskCount <= mTaskCount; taskCount ++){
           myAsyncTask = new MyAsyncTask();
           startMyAsyncTask(myAsyncTask );
       }
   }

    private void displayViewPager(){
        mSectionPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionPagerAdapter);

        mTaskCountIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
        mTaskCountIndicator .setViewPager(mViewPager);
    }

    private void refresh() {
        MyAsyncTask myAsyncTask = null;
        MyAsyncTaskCallBack myAsyncTaskCallBack = new MyAsyncTaskCallBack () {
            @Override
            public void onSuccess() {                   
                   updateViewPager();
                }
            }
        };

        for(int taskCount  = 1; taskCount <= mTaskCount; taskCount ++){
            myAsyncTask = new MyAsyncTask();
            startMyAsyncTask(myAsyncTask );
        }
    }

   private void updateViewPager(){
        mSectionPagerAdapter.setPagerItem(myMap);
        mSectionPagerAdapter.notifyDataSetChanged();
        mCartCountIndicator.notifyDataSetChanged();
         mViewPager.invalidate();
    }
}

Not Sure what am I doing wrong here. Appreciate any suggestion.

Akshay

Okay, figured since it is the activity that is not being refreshed itself I tried this.onResume() in the refresh method once I do notifyDataSetChanged(). It works.

Not sure it is the cleanest solution though

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TabLayout v23 doesn't scroll with ViewPager scroll

From Dev

Submitting a form doesn't work after time, only after refreshing

From Dev

Refreshing page after making changes doesn't render in web browser

From Dev

Refreshing jqGrid doesn't save current page position with infinite scroll enabled

From Dev

ViewPager not refreshing

From Dev

UITableView can't scroll while refreshing

From Dev

Running a Macro after refreshing data

From Dev

refreshing certain data after action

From Dev

angularJS doesn't scroll to top after changing a view

From Dev

Bootstrap modal doesn't scroll after child modal closed

From Dev

jScrollPane doesn't scroll to bottom after content update

From Dev

The scroll detection doesn't work after calling a new page Javascript

From Dev

ListView doesn't show the actual video files after scroll down

From Dev

ViewPager not showing page content / not refreshing after changing the view

From Dev

Foundation 5 top-bar dropdown menu randomly doesn't work, but then works after refreshing the page

From Dev

Manually refreshing partial view doesn't work after automatic ajax refresh

From Dev

ContentDialog doesn't scroll

From Dev

UIWebView doesn't scroll

From Dev

RecyclerView doesn't scroll

From Dev

ViewPager OnPageChangeListener doesn't work

From Dev

ViewPager doesn't show Fragment

From Dev

ViewPager Doesn't work in ScrollView

From Dev

Angular2: Can't get data from service after refreshing page on child component

From Dev

Method doesn't refresh data after DismissViewcontroller

From Dev

refreshing partial view doesn't rerun jquery

From Dev

Refreshing a folder that doesn't exist in the file system

From Dev

Android SQLite Refreshing data on view after modification

From Dev

how to reset jqgrid after refreshing its data

From Dev

Android ListView not refreshing after notifyDataSetChanged with data as Map

Related Related

  1. 1

    TabLayout v23 doesn't scroll with ViewPager scroll

  2. 2

    Submitting a form doesn't work after time, only after refreshing

  3. 3

    Refreshing page after making changes doesn't render in web browser

  4. 4

    Refreshing jqGrid doesn't save current page position with infinite scroll enabled

  5. 5

    ViewPager not refreshing

  6. 6

    UITableView can't scroll while refreshing

  7. 7

    Running a Macro after refreshing data

  8. 8

    refreshing certain data after action

  9. 9

    angularJS doesn't scroll to top after changing a view

  10. 10

    Bootstrap modal doesn't scroll after child modal closed

  11. 11

    jScrollPane doesn't scroll to bottom after content update

  12. 12

    The scroll detection doesn't work after calling a new page Javascript

  13. 13

    ListView doesn't show the actual video files after scroll down

  14. 14

    ViewPager not showing page content / not refreshing after changing the view

  15. 15

    Foundation 5 top-bar dropdown menu randomly doesn't work, but then works after refreshing the page

  16. 16

    Manually refreshing partial view doesn't work after automatic ajax refresh

  17. 17

    ContentDialog doesn't scroll

  18. 18

    UIWebView doesn't scroll

  19. 19

    RecyclerView doesn't scroll

  20. 20

    ViewPager OnPageChangeListener doesn't work

  21. 21

    ViewPager doesn't show Fragment

  22. 22

    ViewPager Doesn't work in ScrollView

  23. 23

    Angular2: Can't get data from service after refreshing page on child component

  24. 24

    Method doesn't refresh data after DismissViewcontroller

  25. 25

    refreshing partial view doesn't rerun jquery

  26. 26

    Refreshing a folder that doesn't exist in the file system

  27. 27

    Android SQLite Refreshing data on view after modification

  28. 28

    how to reset jqgrid after refreshing its data

  29. 29

    Android ListView not refreshing after notifyDataSetChanged with data as Map

HotTag

Archive