Skip to main content

Flash-card app using FragmentPagerAdapter in Android with swipe and Sound

This is yet another flash-card app with swipe navigation and sound play for Android.

Flash-card app using swipe FragmentPagerAdapter 1Flash-card app using swipe FragmentPagerAdapter 2

***Important – am using ADT Bundle of the release 20130917 (adt-bundle-windows-x86_64-20130917). The older version on ADT might use slightly different approach. Download here ***

Create a new Android project.

On the File menu choose New> Android Application Project. Name the Android Application and change the minimum required SDK to API 11.


On the window that provides the navigation type, choose Scrollable Tabs + Swipe.


These are the modifications to be made;

1. Copy the materials (images to drawable, mp3 sound files to assets)


2. Prepare the page layout.

Using the latest IDE, you will get the following layout file named fragment_main_dummy.xml . In the project we are using these IDs; ImageView imgnumber to hold the image number, ImageButton btnsound for the user interaction of playing the sound for the number’s pronunciation.


the fragment_main_dummy.xml

<RelativeLayout xmlns:android=""
tools:context=".MainActivity$DummySectionFragment" >

android:layout_height="match_parent" >

android:layout_height="wrap_content" >

android:src="@drawable/no1" />


android:layout_height="wrap_content" >

android:src="@drawable/sound" />



3. Changing the page titles – open the file res>values>strings.xml, and modify accordingly.


4. The page numbers – find the method getCount, and change accordingly.

public int getCount() {
// Show 3 total pages.
return 3;

5. Make sure the DummySectionFragment class implements OnClickListener – because the sound button need this.

public static class DummySectionFragment extends Fragment implements OnClickListener

6. Declare the necessary UI – just before the method onCreateView inside the DummySectionFragment class.

//put all the mp3 filename as String array
private String[] mp3={"1.mp3","2.mp3","3.mp3"};
private ImageView imgnumber;
private ImageButton btnsound;
private View rootView;
//get the current screen number
private int skrinno;

7. Make the necessary amendment to the onCreateView method.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
skrinno= getArguments().getInt(ARG_SECTION_NUMBER);


//set the screen image
else if(skrinno==2){
else if(skrinno==3){

return rootView;

8. This is the onClick method to handle btnsound click.

public void onClick(View v) {
//button onClick handler
playSound(mp3[skrinno-1]);//array starts from 0
}//end onClick

9. This is the playsound method to play the mp3 sound file.

private MediaPlayer mp;
//the playSound function - copy from
public void playSound(String soundName){
Boolean mpPlayingStatus=false;
mp=new MediaPlayer();

try{//try to check MediaPlayer status
catch (Exception e){
//if the MediaPlayer is playing a sound, stop it to play new sound
if (mpPlayingStatus==true){
mp.stop(); //stop the sound
mp.release(); //remove sound from the memory
mp = new MediaPlayer();
//this is to load the mp3 sound from the assets folder
AssetFileDescriptor afd = rootView.getContext().getAssets().openFd(soundName);
//set the sound source file
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp.prepare(); // prepare for playback
mp.start(); //play the sound
afd.close();//release the file descriptor
}//try block
catch(IOException e) {
//display the error message in debug
Log.i("Error playing sound: ", e.toString());
}//end playSound

The complete code is available for download here –>

Try the app at the Google Play –>

*** Do bookmark/share this in you G+ / FB / Twitter …


Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

Contact Us at

Powered by EMF HTML Contact Form

Login JSON Android using Login Activity

I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and library to do online database with JSON. The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility. STEP 1: Create a new Android project, this time choose the LoginActivity .

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (   ) Available here - Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here Flat-UI is from DesignModo - Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

Pick a file using Intent.ACTION_GET_CONTENT

This tutorial is tested on Honeycomb 3.0 environment. In order to be used it in the lower level of Android API, I believe you could just change the target in the Android project. Screenshots Pick an image file using Intent.ACTION_GET_CONTENT The intention of this project is to choose an image file available in the device storage, and simply display it in an ImageView. The benefit of using Intent.ACTION_GET_CONTENT is you don’t have to develop open dialog box which is not available in the Android library. ACTION_GET_CONTENT with MIME type */* and category CATEGORY_OPENABLE -- Display all pickers for data that can be opened with ContentResolver.openInputStream() , allowing the user to pick one of them and then some data inside of it and returning the resulting URI to the caller. This can be used, for example, image chooser (as shown in this article).