• TekArt

    TekArt is an Organisation where people develop Android App through innovative ideas. App for the next Generation....

Sunday, 6 April 2014

Posted by Unknown
No comments | 22:13
Hello guys, How are you today? I hope you all be in the best of your life.

Today, we are going to see how to show the information in dialog in Android. So , lets get started.



1) First of all, create an Android Application Project.

2) Next go to "res/layout/activity_main.xml" and create a button for which we are going to implement OnClickListener. The code looks like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me"
        android:id="@+id/click" />

</RelativeLayout>

3) Next make an Android xml file in the "res/layout/" folder and create a TextView in there. For our case the name is "show.xml" .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="You are awesome"
        android:textColor="#ffffff"/>
    

</LinearLayout>

4) Next go to "src/your_package_name/MainActivity.java" and implement OnClickListener for the click button. The code looks like

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
    Button click;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        click = (Button) findViewById(R.id.click);
        click.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.click : Intent i = new Intent(this, Show.class);
        startActivity(i);
        break;
        }
    }

}

5) Now, we have to create a class "Show.java" in the "src/your_package_name" . In Show.java we are going to display the show.xml.

import android.app.Activity;
import android.os.Bundle;

public class Show extends Activity{
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
        
    
    }

}

6) Now open AndroidManifest,xml and create an Show Activity with the dialog theme.

For our case its like
<activity android:theme="@android:style/Theme.Dialog" android:name="com.example.dialog_blog.Show" />

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you
Posted by Unknown
2 comments | 00:07
Hello Guys , How are you?? Its Super Sunday, hope you guys enjoying your weekend.

Today we will see how to Play Videos in Android. So lets get started.



1) First of all create an Android Application Project.

2) Go to "res/layout/activity_main.xml" and create a VideoView. The code looks like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <VideoView  
        android:id="@+id/videoView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentLeft="true"  
        android:layout_centerVertical="true" />  

</RelativeLayout>



3) Next go to "src/your_package_name/MainActivity.java" and create set the MediaController for VideoView.

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        VideoView videoView = (VideoView) findViewById(R.id.videoView1);

        // Creating MediaController
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);

        // specify the location of media file
        Uri uri = Uri.parse("android.resource://com.example.videoplayer_blog/"
                + R.raw.video1);

        // Setting MediaController and URI, then starting the videoView
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();
    }

}

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Saturday, 5 April 2014

Posted by Unknown
No comments | 02:54
Hello guys, how are you today? Its super Saturday, i hope you guys will be enjoying your weekend.

In this blog we are going to see how to work with the checkboxes in android. So lets get started.



1) First of all  create an Android Application Project.

2) Go to "res/layout/activity_main.xml" and create 4 checkboxes thereselect, android, windows, ios. The code looks like

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical" >
    
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select all"
        android:id="@+id/select" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Android"
        android:id="@+id/android" />
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Windows"
        android:id="@+id/win" />
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="iOS"
        android:id="@+id/ios" />
    

</LinearLayout>


3) Next go to "src/your_package_name/MainActivity.java" and here we will implement OnCheckedChangeListener for all the checkboxes. On clicking the "select all" checkbox all the rest checkboxes should get selected and on unselecting it the rest should get unselected.

The code for MainActivity is given below

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;

public class MainActivity extends Activity implements OnCheckedChangeListener {
    CheckBox select, android, win, ios;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        select = (CheckBox) findViewById(R.id.select);
        android = (CheckBox) findViewById(R.id.android);
        win = (CheckBox) findViewById(R.id.win);
        ios = (CheckBox) findViewById(R.id.ios);

        select.setOnCheckedChangeListener(this);
        android.setOnCheckedChangeListener(this);
        win.setOnCheckedChangeListener(this);
        ios.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
        case R.id.select:
            if (select.isChecked())
                select_all();
            else
                unselect_all();
            break;

        case R.id.android:
            if (android.isChecked())
                Toast.makeText(this, "Android is selected", Toast.LENGTH_SHORT)
                        .show();
            else
                Toast.makeText(this, "Android is unselected",
                        Toast.LENGTH_SHORT).show();
            break;

        case R.id.win:
            if (win.isChecked())
                Toast.makeText(this, "Windows is selected", Toast.LENGTH_SHORT)
                        .show();
            else
                Toast.makeText(this, "Windows is unselected",
                        Toast.LENGTH_SHORT).show();
            break;

        case R.id.ios:
            if (ios.isChecked())
                Toast.makeText(this, "ios is selected", Toast.LENGTH_SHORT)
                        .show();
            else
                Toast.makeText(this, "ios is unselected", Toast.LENGTH_SHORT)
                        .show();
            break;
        }
    }

    private void select_all() {
        // TODO Auto-generated method stub
        android.setChecked(true);
        win.setChecked(true);
        ios.setChecked(true);
    }

    private void unselect_all() {
        // TODO Auto-generated method stub
        android.setChecked(false);
        win.setChecked(false);
        ios.setChecked(false);
    }

}


Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Thursday, 3 April 2014

Posted by Unknown
2 comments | 23:27
Hello Guys , how are you today? Its super Friday.

In this blog e are going to see how to make an image slideshow with button and music controls in Android. So ,lets get started.



1) First of all create an Android Application Project.

2) Go to "res/layout/activity_main.xml" and create two image buttons there. This code looks like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity"

    android:background="@drawable/costume1"

    android:id ="@+id/back" >



    <ImageButton 

        android:layout_height="wrap_content"

        android:layout_width = "wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_centerInParent="true"

        android:layout_centerHorizontal="true"

        android:src="@drawable/left"

        android:background="@null"

        android:id="@+id/left"

        android:alpha="0.5"

        />

    

    <ImageButton 

        android:layout_height="wrap_content"

        android:layout_width = "wrap_content"

        android:layout_alignParentRight="true"

        android:layout_centerInParent="true"

        android:layout_centerHorizontal="true"

        android:src="@drawable/right"

        android:background="@null"

        android:id="@+id/right"

        android:alpha="0.5"/>



    <ImageButton

        android:id="@+id/music"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:layout_alignParentRight="true"

        android:background="@null"

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



</RelativeLayout>


The images used here can be get through the project file in the download link above.

3) Now go to "src/your_package_name/MainActivity.java" and copy paste the below code.

import java.util.ArrayList;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.app.Activity;

import android.content.res.Resources;

import android.graphics.drawable.Drawable;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.ImageButton;

import android.widget.RelativeLayout;



public class MainActivity extends Activity implements OnClickListener {

    

    ImageButton left,right,music;

    MediaPlayer mp;

    RelativeLayout back;

    ArrayList<Integer> imagearray;

    Resources res;Drawable drawable;

    int track=0;boolean flag=false;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        

        imagearray = new ArrayList<Integer>();

        

        back = (RelativeLayout) findViewById(R.id.back);

        left= (ImageButton) findViewById(R.id.left);

        right= (ImageButton) findViewById(R.id.right);

        music= (ImageButton) findViewById(R.id.music);

        //left.setAlpha(45);

        //right.getBackground().setAlpha(45);

        left.setOnClickListener(this);

        right.setOnClickListener(this);

        music.setOnClickListener(this);

        setup();

        res = getResources(); 

    }



    private void setup() {

        // TODO Auto-generated method stub

        imagearray.add(R.drawable.costume1);

        imagearray.add(R.drawable.costume2);

        imagearray.add(R.drawable.costume3);

        imagearray.add(R.drawable.costume4);

        imagearray.add(R.drawable.costume5);

        

        if(track==0) {

            left.setEnabled(false);

            left.setVisibility(View.GONE);

        }

        

        mp=MediaPlayer.create(this, R.raw.music);

        mp.start();

    }



    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        //getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }



    @Override

    public void onClick(View v) {

        // TODO Auto-generated method stub

        switch(v.getId()) {

        case R.id.left: if(track!=0)track--;

        checkview();

        //drawable = res.getDrawable(imagearray.get(track));

        back.setBackgroundResource(imagearray.get(track));

        break;

        

        case R.id.right: if(track!=imagearray.size()-1) track++;

        checkview();

        //drawable = res.getDrawable(imagearray.get(track));

        back.setBackgroundResource(imagearray.get(track));

        break;

        

        case R.id.music : if(!flag){

            mp.pause();

            music.setImageResource(R.drawable.sound1);

            flag = true;

        }else{

            flag = false;

            mp.start();

            music.setImageResource(R.drawable.mute1);

        }

        }

    }



    private void checkview() {

        // TODO Auto-generated method stub

        if(track==0) {

            left.setEnabled(false);

            left.setVisibility(View.GONE);

        }else {

            left.setEnabled(true);

            left.setVisibility(View.VISIBLE);

        }

        if(track==imagearray.size()-1) {

            right.setEnabled(false);

            right.setVisibility(View.GONE);

        }else {

            right.setEnabled(true);

            right.setVisibility(View.VISIBLE);

        }

    }

    



}


In this code we are traversing the arraylist using a variable track and changing the background of relativelayout accordingly.

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Posted by Unknown
1 comment | 21:46
Hello Guys, how are you today? Its super Friday. Hope having a good day.

Today we are going to see how to use MediaPlayer for for performing basic operations like play, pause, stop in Android. So lets get started.



1) First of all, create an Android Application Project.

2) Then go to "res/layout/activity_main.xml" and create 3 buttons there play, pause and stop. So the code looks like.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity"

    android:orientation="vertical"

     >



    <Button

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="Play"

        android:id="@+id/play"

        android:layout_gravity="center" />

    

    <Button

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="Pause"

        android:id="@+id/pause"

        android:layout_gravity="center" />

    

    <Button

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="Stop"

        android:id="@+id/stop"

        android:layout_gravity="center" />



</LinearLayout>

3) Now we are going to implement OnClickListener for all these buttons and do some operations on clicking those buttons. Before that we create a folder "raw" in "res/" . In raw folder we store a music file "music.mp3" .

4) Now we are going to create a MediaPlayer object mp and going to use for performing our tasks.

    MediaPlayer mp;

5) In the onClick event of play button we are going to play the music. So, our code will be

     mp = MediaPlayer.create(this, R.raw.music);
     mp.start();

6) In the onClick event of pause button we are going to pause the music. So, our code will be

    mp.pause();

7)  In the onClick event of stopbutton we are going to stop the music. So, our code will be

     mp.stop();

The final code looks like

import android.app.Activity;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;



public class MainActivity extends Activity implements OnClickListener {

    MediaPlayer mp;

    Button play, pause,stop;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

       

        play = (Button) findViewById(R.id.play);

        pause = (Button) findViewById(R.id.pause);

        stop  =(Button) findViewById(R.id.stop);

        play.setOnClickListener(this);

        pause.setOnClickListener(this);

        stop.setOnClickListener(this);

    }



    @Override

    public void onClick(View v) {

        // TODO Auto-generated method stub

        switch(v.getId()) {
  case R.id.play : if(mp == null) {
   mp = MediaPlayer.create(this, R.raw.music);
   
  }
  mp.start();
  break;
  case R.id.pause : mp.pause();break;
  
  case R.id.stop : mp.stop();mp = null;break;
  }

       

    }



}


Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you


Wednesday, 2 April 2014

Posted by Unknown
1 comment | 06:37
Hello guys, How are you today?? Hope, fine. Today we are going to see about how to create popup selector in Android. So , lets get started.


Download Pop up Selector

1) First of all create an Android Application Project.

2) Now go to "res/layout/activity_main.xml" and create a button. For our case we made the button "show popup". The code is here.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

   <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/popup"
       android:text="Show pop up"
       android:layout_centerHorizontal="true"
       android:layout_centerVertical="true"/>

</RelativeLayout>

3) Now we have to implement OnClickListener for this button, so we implement OnClickListener in the MainActivity class. OnClicking the button popup window should be created.So for creating the popup we need to use AlertDialog.Builder . The code for building the popup is below.

private void build_popup() {
       // AlertDialog Builder for building our builder
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Demo Popup");

   
        // we provided single selected options only. For multiple selections you can use the function
// builder.setMultipleChoiceItems(syntax is same to setSingleChoiceItems)
        builder.setSingleChoiceItems(R.array.arr, selected, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                temp = which;
            }

           
           
        });
       
       // for building Ok button
        builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                selected = temp;
               
                switch(selected) {
               
                case 0:text = "Bad";break;
               
                case 1:text = "Good";break;
               
                case 2:text = "Very Good";break;
               
                case 3:text = "Average";break;
               
                }
                Toast.makeText(MainActivity.this, "You Selected " + text, Toast.LENGTH_LONG).show();
               
            }
        });
       
    //for building Cancel button
        builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            dialog.cancel();   
            }
        });
       
        AlertDialog al =builder.create();
        al.show();
    }

I have written the comments which will help you guys to better understand the code.

4) So our full code looks like.

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
    Button popup;
    int selected =0;
    int temp;String text="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        popup = (Button) findViewById(R.id.popup);
        popup.setOnClickListener(this);
    }

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

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.popup: build_popup();break;
        }
    }

    private void build_popup() {
        // TODO Auto-generated method stub
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Demo Popup");
       
        builder.setSingleChoiceItems(R.array.arr, selected, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                temp = which;
            }

           
           
        });
       
        builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                selected = temp;
               
                switch(selected) {
               
                case 0:text = "Bad";break;
               
                case 1:text = "Good";break;
               
                case 2:text = "Very Good";break;
               
                case 3:text = "Average";break;
               
                }
                Toast.makeText(MainActivity.this, "You Selected " + text, Toast.LENGTH_LONG).show();
               
            }
        });
       
        builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            dialog.cancel();   
            }
        });
       
        AlertDialog al =builder.create();
        al.show();
    }

}

Now we are done.

For any queries post in the comment.

For more info visit Androidcoolstuffs.

Thank you.












Tuesday, 1 April 2014

Posted by Unknown
No comments | 03:38
Hello Guys , how are you today. In this Blog, we are going to see how to work with android TextToSpeech. So lets get started.



Download TextToSpeech

1) First make an Android Application Project.

2) Open "res/layout/activity_main.xml" and create an EditText and a Button there. For our case the code is below.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical" >
   
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/word"/>
   

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Say it"
        android:id="@+id/say"/>

</LinearLayout>

3) Now open "src/your_package_name/MainActivity.java" and create a TextToSpeech Object. I will tell you how to do that .

TextToSpeech tts;

4) Now implement MainActivity to TextToSpeech.OnInitListener. In eclipse you will see error which can be removed by clicking on "add unimplemented function" . So the new function looks like.

@Override
    public void onInit(int status) {
        // TODO Auto-generated method stub
        if(status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.US);
            tts.setPitch((float) 60.0);
            if(result==TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Toast.makeText(this, "Languauge Not Supported", Toast.LENGTH_LONG).show();
                Log.e("TTS", "Languauge Not Supported");
            }else {
               
            }
        }else {
            Toast.makeText(this, "Device Not Supported for Text To Speech", Toast.LENGTH_LONG).show();
            Log.e("TTS", "Initialisation failed");
        }
       
    }

I think this function is self explanatory.

5) The device can be made to speak using the following single line code.

tts.speak(word.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);

6) The whole code looks like  below.

import java.util.Locale;

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements TextToSpeech.OnInitListener,OnClickListener {
    EditText word;
    Button say;
    TextToSpeech tts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        word = (EditText) findViewById(R.id.word);
        say = (Button) findViewById(R.id.say);
       
        tts = new TextToSpeech(this, this);
        say.setOnClickListener(this);
    }

   

    @Override
    public void onInit(int status) {
        // TODO Auto-generated method stub
        if(status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.US);
            tts.setPitch((float) 60.0);
            if(result==TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Toast.makeText(this, "Languauge Not Supported", Toast.LENGTH_LONG).show();
                Log.e("TTS", "Languauge Not Supported");
            }else {
               
            }
        }else {
            Toast.makeText(this, "Device Not Supported for Text To Speech", Toast.LENGTH_LONG).show();
            Log.e("TTS", "Initialisation failed");
        }
       
    }
   
    private void speak() {
        tts.speak(word.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.say :speak();break;
        }
    }

}

Now we are done. For any queries pls comment .

Thank You

For More Info visit https://www.facebook.com/androidcoolstuffs