Aug 31, 2017 Home Forums Android Discussion Android Apps & Games Tasker How to use sliders Discussion in ' Android Apps & Games ' started by Aniruddha060, Aug 30, 2017. Q: I wonder if you could help me to implementing wowslide for jquery mobile, or point me to any documentation that would support this, or any create mobile website templates with this facility, any input would be welcome!!! A: Actually, slideshows generated with wowslider app. Are displayed on portable devices (iPhone / iPad / Android) correctly. Wowslider supports swipe touch events for these. Android Project. Create a new Android project and name it as AndroidImageSlideShow. Download “Android Image Slideshow using ViewPager” ImageViewSlideshow.zip – Downloaded 22763 times – 2 MB. Resources colors.xml. Create a new file res/values/colors.xml and copy paste the following content.
Earlier we have discussed, the working of android view pager by implementing FragmentPagerAdapter in Android Viewpager Example Tutorial. Now we will discuss how to create android image slideshow by extending android pagerAdapter.
Let’s create an android image slideshow example to run a slide show of popular X-MEN posters.
Contents
- 1 Create Android Image Slider App
- 2 Add Layout for Android Image Slideshow
- 3 Implement Android Image Slider using ViewPager
Create Android Image Slider App
- Go to File → New → New Project and enter your Application Name. Let’s say Android Image Slider
- Enter company domain, this is used to uniquely identify your App’s package worldwide.
- Choose project location and minimum SDK and on the next screen choose Simple Activity, since we would be adding most of the code Ourselves. Then Click on Next.
- Choose an Activity Name. Make sure Generate Layout File check box is selected, Otherwise we have to generate it ourselves.Then click on Finish. We have kept the Activity Name as MainActivity.java. This will be the default screen when the user opens the app for the first time.
Gradle will configure your project and resolve the dependencies, Once it is complete proceed to the next steps.
We need to add the dependency for CircleIndicator in the app’s build.gradle file.
build.gradle
Add Layout for Android Image Slideshow
- Add the following code to the activity_main.xml. The layout consist of an Android ViewPager and a CircleIndicator wrapped inside a RelativeLayout.
- Now Let’s add the code for layout of each slide that will be shown in the Android Image Slider. Add the following code in the slide.xml file. It consists of an ImageView wrapped in a FrameLayout.
activity_main.xml
slide.xml
Implement Android Image Slider using ViewPager
- To create android image slideshow, We will hook up a PagerAdapter to android ViewPager.Create a new class MyAdapter.java and add the following code.
- instantiateItem(ViewGroup, int) – This method should create the page for the positiion passed to it as an argument. Here we inflate() the slide.xml layout to create the android images slider set the image resource for the ImageView in it. Finally, the inflated view is added to the ViewPager using addView() and return it.
- destroyItem(ViewGroup, int, Object) – Removes the page for the given position from the container. Here we have simply removed object using removeView().
- getCount() – returns the number of available views in the ViewPager.
- isViewFromObject(View, Object) – This method checks whether the view passed to it is associated with the key returned by the instantiateItem(). This method is important for proper functioning of the PagerAdapter. We just compare the two input view and the key and return the result.
- Next, Let’s implement the android image slider. Add the following code to your MainActivity.java
MyAdapter.java
MyAdapter.java will popluate the custom content in our ViewPager:
To implement the abstract class PagerAdapter. We need to override the following methods which have been defined as abstract methods.
MainActivity.java
We have created an Array containing the images of X-MEN poster, We get the data set from XMEN Array – the List of X-MEN posters. After that, we reference the ViewPager in the activity’s view and then set the adapter to be an unnamed instance of MyAdapter.
Next, we reference the CircleIndicator and use the setViewPager to set the indicator.
To create android image slider effect. We have used a Handler to update the android image slider on a new thread. Then we use Timer to schedule tasks for repeated execution in a background thread at an interval of 2.5 seconds starting with a delay of 2.5 seconds.
Download Bannerslider.jar For Android Pc
Now run the Android Image Slider app on an emulator or an actual Android Device and you should see a beautiful android image slideshow. Try to experiment with image slider in your app and
What’s Next ??
After this, We will be covering more interesting tutorials like creating a multilingual app in android.
Till then stay tuned for more tutorials.. and Don’t forget to subscribe our blog for latest android tutorials. Also do Like our Facebook Page or Add us on Twitter.
Till then stay tuned for more tutorials.. and Don’t forget to subscribe our blog for latest android tutorials. Also do Like our Facebook Page or Add us on Twitter.
To download the full code for the Android Image Slider Tutorial using the android studio, Click on the Download Now link below.