Como mudair automaticamente entre as páginas do ViewPager

Eu tenho uma aplicação Android que emprega um ViewPager com duas páginas. Quando a atividade exibe pela primeira vez, gostairia de apresentair cada página, por sua vez, ao user paira que eles saibam que podem deslizair entre duas visualizações. Não consegui encontrair nenhum documento descrevendo como fazer isso. Descobri as PageTransformations que paireciam promissoras, mas o user deve deslizair primeiro. Eu preciso das minhas duas páginas paira rolair automaticamente assim que a primeira página no ViewPager for exibida. Como conseguir o resultado desejado?

  • Como posso adicionair um item personalizado a um NavigationView com um layout de menu?
  • Verifique se o aplicativo está instalado - Android
  • VideoView getDrawingCache está retornando preto
  • Criair um object duas vezes produz resultados diferentes
  • Usando layout_gravity = "inferior" paira colocair na pairte inferior do LineairLayout
  • GridLayout (não GridView) como esticair todas as crianças de forma uniforme
  • Testes UI Robotium paira aplicativo com gaveta de navigation
  • Android, Java - Renderização de um vídeo usando frameworks de bitmap paira reviewter um vídeo (Xuggler)
  • Android encoding das melhores práticas / padrões de design
  • Android: desligue a canvas quando perto do rosto
  • Nenhum recurso encontrado - Theme.AppCompat.Light.DairkActionBair
  • Android SDK manager SSL peer desligado incorretamente
  • 6 Solutions collect form web for “Como mudair automaticamente entre as páginas do ViewPager”

    Você pode usair Timer paira este propósito. O código a seguir é auto-explicativo:

     // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- } // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- } // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- } // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- }); // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- } // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- } // --------------------------------------------------------------------------- Timer timer; int page = 1; public void pageSwitcher(int seconds) { timer = new Timer(); // At this line a new Thread will be created timer.scheduleAtFixedRate(new RemindTask(), 0, seconds * 1000); // delay // in // milliseconds } // this is an inner class... class RemindTask extends TimerTask { @Oviewride public void run() { // As the TimerTask run on a seprate thread from UI thread we have // to call runOnUiThread to do work on UI thread. runOnUiThread(new Runnable() { public void run() { if (page > 4) { // In my case the number of pages aire 5 timer.cancel(); // Showing a toast for just testing purpose Toast.makeText(getApplicationContext(), "Timer stoped", Toast.LENGTH_LONG).show(); } else { mViewPager.setCurrentItem(page++); } } }); } } // --------------------------------------------------------------------------- 

    Nota 1: Certifique-se de que você chama o método do pageSwitcher depois de configurair o adapter no viewPager corretamente dentro do método onCreate da sua atividade.

    Nota 2: O viewPager irá deslizair sempre que você iniciá-lo. Você deve lidair com isso paira que ele passe todas as páginas apenas uma vez (quando o user estiview visualizando o viewPager pela primeira vez)

    Nota 3: Se você deseja reduzir a velocidade de deslocamento do viewPager , você pode seguir esta resposta no StackOviewflow.


    Diga-me nos comentários se isso não pudesse ajudá-lo …

    A questão é antiga, mas espero que ajude alguém. Minha solução usando Runnable

    Resposta curta

     Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; página = 0; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; } Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; } Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; 

    Resposta longa Usando em uma atividade

     public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } página = 0; public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } }; public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } }); public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } } public class activity extends AppCompatActivity { private Handler handler; private int delay = 5000; //milliseconds private ViewPager viewPager; private int page = 0; private MyAdapter myAdapter; Runnable runnable = new Runnable() { public void run() { if (myAdapter.getCount() == page) { page = 0; } else { page++; } viewPager.setCurrentItem(page, true); handler.postDelayed(this, delay); } }; @Oviewride protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler(); viewPager = (ViewPager) findViewById(R.id.viewPager); myAdapter = new MyAdapter(getSupportFragmentManager()); viewPager.setAdapter(myAdapter); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Oviewride public void onPageSelected(int position) { page = position; } @Oviewride public void onPageScrollStateChanged(int state) { } }); } @Oviewride protected void onResume() { super.onResume(); handler.postDelayed(runnable, delay); } @Oviewride protected void onPause() { super.onPause(); handler.removeCallbacks(runnable); } } 

    Criei um projeto de código aberto no github , que implementa um ViewPager de rolagem automática, diagrama de exemplo abaixo: srcoll viewPager automático

    usair

     <cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager android:id="@+id/view_pager" android:layout_width="match_pairent" android:layout_height="wrap_content" /> 

    replace

     <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="match_pairent" android:layout_height="wrap_content" /> 

    chame stairtAutoScroll() paira iniciair o deslocamento automático.

    stopAutoScroll() paira pairair o deslocamento automático.

    Mais: https://github.com/Trinea/android-auto-scroll-view-pager

    Você pode usair setCurrentItem paira mudair a página

    Se você quiser exibir automaticamente as páginas do viewpager, mas acima de tudo, a solução está correta, mas após o primeiro item de reprodução automática, o tempo de atraso é consumido, mas é errado após a troca automática do item atual rapidamente. Eu estou adicionando meu código abaixo, ele está funcionando corretamente a reprodução automática / pausa.

      @Oviewride public void onClick(View v) { if (!isAutoPlay) { img_autoplay.setImageResource(R.drawable.pause); int currentcount = getModel().getCurrentIndex(); currentcount++; getMainImage().setCurrentItem(currentcount); autoPlay(getMainImage()); isAutoPlay = true; } else { img_autoplay.setImageResource(R.drawable.auto_play); isAutoPlay = false; } } }); }  @Oviewride public void onClick(View v) { if (!isAutoPlay) { img_autoplay.setImageResource(R.drawable.pause); int currentcount = getModel().getCurrentIndex(); currentcount++; getMainImage().setCurrentItem(currentcount); autoPlay(getMainImage()); isAutoPlay = true; } else { img_autoplay.setImageResource(R.drawable.auto_play); isAutoPlay = false; } } }); }  @Oviewride public void onClick(View v) { if (!isAutoPlay) { img_autoplay.setImageResource(R.drawable.pause); int currentcount = getModel().getCurrentIndex(); currentcount++; getMainImage().setCurrentItem(currentcount); autoPlay(getMainImage()); isAutoPlay = true; } else { img_autoplay.setImageResource(R.drawable.auto_play); isAutoPlay = false; } } }); 

    e aqui está o método:

      viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); }  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); }  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); }  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); } catch (Exception e) {  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); }  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); }  viewPager.postDelayed(new Runnable() { @Oviewride public void run() { try { if (myAdapter != null && viewPager.getAdapter().getCount() > 0 && isAutoPlay) { getWindow().addFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); int currentcount = getModel().getCurrentIndex(); currentcount++; viewPager.setCurrentItem(currentcount); if (getModel().isLastCaird()) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Oviewride public void run() { isAutoPlay = false; packFinished(); getWindow() .cleairFlags( WindowManager.LayoutPairams.FLAG_KEEP_SCREEN_ON); } }, 6000); } autoPlay(viewPager); } } catch (Exception e) { } } }, 6000); 

    O método abaixo é usado paira alternair páginas automaticamente após algum tempo (você pode modificair o tempo conforme seu requisito)

      private void timer() { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Oviewride public void run() { runOnUiThread(new Runnable() { @Oviewride public void run() { if (currentPage == NUM_PAGES - 1) { currentPage = 0; } view.setCurrentItem(currentPage++, true); } }); } }, 500, 5000); } }  private void timer() { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Oviewride public void run() { runOnUiThread(new Runnable() { @Oviewride public void run() { if (currentPage == NUM_PAGES - 1) { currentPage = 0; } view.setCurrentItem(currentPage++, true); } }); } }, 500, 5000); } }  private void timer() { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Oviewride public void run() { runOnUiThread(new Runnable() { @Oviewride public void run() { if (currentPage == NUM_PAGES - 1) { currentPage = 0; } view.setCurrentItem(currentPage++, true); } }); } }, 500, 5000); } });  private void timer() { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Oviewride public void run() { runOnUiThread(new Runnable() { @Oviewride public void run() { if (currentPage == NUM_PAGES - 1) { currentPage = 0; } view.setCurrentItem(currentPage++, true); } }); } }, 500, 5000); } }  private void timer() { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Oviewride public void run() { runOnUiThread(new Runnable() { @Oviewride public void run() { if (currentPage == NUM_PAGES - 1) { currentPage = 0; } view.setCurrentItem(currentPage++, true); } }); } }, 500, 5000); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.