title: how to slide images automatically along by sliding custom by fingers
body: <p>I have implemented an image slider with dots. Working perfectly. Slider is working only on manual by sliding from finger left or right not automatically by a time interval 3 seconds.</p>
  
  <p>See the code and suggest me some approach to working slider automatically.
  ViewPager in .xml layout file</p>
  
  <pre><code>&lt;androidx.viewpager.widget.ViewPager
              android:id="@+id/view_pager"
              android:layout_width="match_parent"
              android:layout_height="160dp"
              android:layout_alignParentTop="true" /&gt;
          &lt;LinearLayout
              android:paddingTop="8dp"
              android:id="@+id/slider_dots"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:gravity="center_horizontal|center_vertical"
              android:layout_below="@id/view_pager"&gt;&lt;/LinearLayout&gt;
  
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here's ViewPageAdapter java class</p>
  
  <pre><code>public class ViewPagerAdapter extends PagerAdapter {
      Context context;
      LayoutInflater layoutInflater;
      int images[] = {R.mipmap.banner, R.mipmap.banner1, R.mipmap.banner2, R.mipmap.banner3, R.mipmap.banner4, R.mipmap.banner5};
  
      public ViewPagerAdapter(Context context) {
          this.context = context;
      }
  
      @Override
      public int getCount() {
          return images.length;
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view == object;
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
          View view = layoutInflater.inflate(R.layout.slider_banner_layout, null);
          ImageView imageView = view.findViewById(R.id.image_view_banner_image);
          imageView.setImageResource(images[position]);
  
          ViewPager viewPager = (ViewPager) container;
          viewPager.addView(view, 0);
          return view;
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          ViewPager viewPager = (ViewPager) container;
          View view = (View) object;
          viewPager.removeView(view);
      }
  }
  </code></pre>
  
  <p>MainActivity.java </p>
  
  <pre><code>public class HomeActivity extends AppCompatActivity {
      ViewPager viewPager;
      LinearLayout sliderDotsPanel;
      ImageView[] dots;
      private int dotCount;
      ViewPagerAdapter viewPagerAdapter;
      private Toolbar toolbar;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_home);
  
          toolbar = findViewById(R.id.app_bar);
          toolbar.setTitle("");
          toolbar.setLogo(R.mipmap.toolbar_logo);
          setSupportActionBar(toolbar);
  
          viewPager = findViewById(R.id.view_pager);
          viewPagerAdapter= new ViewPagerAdapter(this);
          viewPager.setAdapter(viewPagerAdapter);
          sliderDotsPanel=findViewById(R.id.slider_dots);
          initializeDots();
     }
     private void initializeDots() {
          dotCount = viewPagerAdapter.getCount();
          dots = new ImageView[dotCount];
          for (int i = 0; i &lt; dotCount; i++) {
              dots[i] = new ImageView(this);
              dots[i].setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.non_active_dot));
              LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
              params.setMargins(8, 0, 8, 0);
              sliderDotsPanel.addView(dots[i], params);
          }
          dots[0].setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.active_dot));
          viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
              @Override
              public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
              }
  
              @Override
              public void onPageSelected(int position) {
                  for (int i = 0; i &lt; dotCount; i++) {
                      dots[i].setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.non_active_dot));
                  }
                  dots[position].setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.active_dot));
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
  
              }
          });
      }
  }
  </code></pre>