Saturday 30 November 2013

R cannot be resolved to a variable.

R cannot be resolved to a variable

R cannot be resolved to a variable or R.java file missing????
This is the most common error which occurs.
There are simple testing to overcome this error.

1.Check all the xml files in <my project>/res folder.
2.xml files means it may be layout files,string.xml, dimens.xml, styles.xml.

This error is occured because the ADT cannot build the code if there's any error in xml file, by which the project will not generate the automated generated java file means R.java file.

Thursday 28 November 2013

How to get the source code from apk file.

How to get the source code from apk file.

So all are eager to know how to extract the code from apk file.
So here are the simple steps to extract.
Just follow the below steps to get.
Here is the 
Windows software
Mac OS X
Linux
 u need to download to extract.

Step 1. Rename the .apk file you wish to retrieve and change the extension to .zip. Then extract the file that it creates.

Step 2. Copy the contents of the dex2jar folder to the extracted folder to make it easier for yourself, and run:

            dex2jar classes.dex

and copy the resulting “classes.dex.dex2jar.jar” into a new folder.

Step 3. Open up the Java Decompiler and drag “classes.dex.dex2jar.jar” into the window and then go to File > Save and save the source in a .zip file.


Step 4. Extract the saved .zip and copy the contents to a new folder somewhere. This will be where we keep your source code.


Step 5. Now, copy “framework-res.apk” and “yourapk.apk” to the APKTool folder. Then open a command prompt or Terminal window and type:

              apktool if framework-res.apk
              apktool d <yourapk.apk>

Step 6. Now just copy the contents of the resulting folder to the same place you copied the contents of “classes.dex.dex2jar.jar” earlier and voila, you have your source code. You may need to remove a couple of things, but your entire code should be there!

Friday 1 November 2013

Conversion to Dalvik format failed with error 1

Conversion to Dalvik format failed with error 1

This is the major error which is caused while adding libraries in android.


The cause of the error is having two same jar files in <my-project>/lib folder.

The Jar file may be having different names but same functionality.
I suggest you to delete all the jar files from the my-project/lib folder and then

  1. Right click on the project and click the fix project properties in Android tools.
  2. Add the required jar files.
  3. Remove the Build Automatically option from project menu.
  4. Clean the project from the project menu.
  5. Rebuild the project now.

SO check that

To overcome this just delete one of the jar file in lib folder that's it.



Saturday 28 September 2013

Context Menu in Android

In previous topic we learnt the simple menu, So let's learn how to create context menu in android.

A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.

Now let's create it.
1. MainActivity.java

package com.sri.menus;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

final int MENU_RED = 1;
final int MENU_GREEN = 2;
final int MENU_BLUE = 3;

final int MENU_SIZE_22 = 4;
final int MENU_SIZE_26 = 5;
final int MENU_SIZE_30 = 6;

TextView tvColor, tvSize;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvColor = (TextView) findViewById(R.id.tvColor);
tvSize = (TextView) findViewById(R.id.tvSize);

// context menu should be created for tvColor and tvSize
registerForContextMenu(tvColor);
registerForContextMenu(tvSize);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
switch (v.getId()) {
case R.id.tvColor:
menu.add(0, MENU_RED, 0, "Red");
menu.add(0, MENU_GREEN, 0, "Green");
menu.add(0, MENU_BLUE, 0, "Blue");
break;
case R.id.tvSize:
menu.add(0, MENU_SIZE_22, 0, "22");
menu.add(0, MENU_SIZE_26, 0, "26");
menu.add(0, MENU_SIZE_30, 0, "30");
break;
}
}

@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
// menu items for tvColor
case MENU_RED:
tvColor.setTextColor(Color.RED);
tvColor.setText("Text color = red");
break;
case MENU_GREEN:
tvColor.setTextColor(Color.GREEN);
tvColor.setText("Text color = green");
break;
case MENU_BLUE:
tvColor.setTextColor(Color.BLUE);
tvColor.setText("Text color = blue");
break;
// menu items for tvSize
case MENU_SIZE_22:
tvSize.setTextSize(22);
tvSize.setText("Text size = 22");
break;
case MENU_SIZE_26:
tvSize.setTextSize(26);
tvSize.setText("Text size = 26");
break;
case MENU_SIZE_30:
tvSize.setTextSize(30);
tvSize.setText("Text size = 30");
break;
}
return super.onContextItemSelected(item);
}

}

2.activity_main.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:id="@+id/tvColor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="50dp"
        android:text="Text color"
        android:textSize="26sp" >
    </TextView>

    <TextView
        android:id="@+id/tvSize"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Text size"
        android:textSize="22sp" >
    </TextView>


</LinearLayout>

3.That's it.

Simples Menus in Android

How to add simple menu in android?


Now lets Create a simple menu item in android.
There are 3 types of menu in android.
1.Options menu
2.Context menu
3.Popup menu

First we'll discuss about options menu

1.MainActivity.java

package com.sri.menus;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends Activity {

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

@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 boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.m1:
Toast.makeText(getApplicationContext(), "menu 1",
Toast.LENGTH_SHORT).show();
break;
case R.id.m2:
Toast.makeText(getApplicationContext(), "menu 2",
Toast.LENGTH_SHORT).show();
default:
break;
}
return super.onOptionsItemSelected(item);
}

}


2.activity_main.xml

<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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Displaying Menu" />

</RelativeLayout>

3. Check in res/menu folder the main.xml
in that

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

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/m1"
        android:showAsAction="ifRoom"
        android:title="menu 1"/>
    <item
        android:id="@+id/m2"
        android:showAsAction="ifRoom"
        android:title="menu 2"/>

</menu>

4. In main.xml, the android:showAsAction="ifRoom" is written to show it on the action bar and have the more priority.
android:showAsAction="never" is used to hide in the menu and show's on more button.

5.That's it now run it.

Friday 27 September 2013

POPUP window in android

How to Display Popup Window in Android?


Friends, Lets learn how to display a popup window in android.
Popup is different from Dialog Box. Dialog has the priority to display in only center of the screen but popup can be displayed anywhere in the screen.

Now let's start with the
1.MainActivity.java

package com.sri.popup;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class MainActivity extends Activity {
private Button btnShowPopUp;
private PopupWindow mpopup;

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

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

btnShowPopUp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
View popUpView = getLayoutInflater().inflate(R.layout.popup,
null); // inflating popup layout
mpopup = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT, true); // Creation of popup
mpopup.setAnimationStyle(android.R.style.Animation_Dialog);
mpopup.showAtLocation(popUpView, Gravity.BOTTOM, 20, 20); // Displaying
// popup

Button btnOk = (Button) popUpView.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mpopup.dismiss(); // dismissing the popup
}
});

Button btnCancel = (Button) popUpView
.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mpopup.dismiss(); // dismissing the popup
}
});
}
});
}
}

2.activity_main.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" >

    <Button
        android:id="@+id/btnShowPopUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show PopUp" >
    </Button>

</LinearLayout>



3.Add the new xml file in the res/layout folder as popup.xml
popup.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="wrap_content"
    android:background="#90FFFFFF"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="PopUp Window"
        android:textColor="#000000"
        android:textStyle="bold" >
    </TextView>

    <Button
        android:id="@+id/btnOk"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Ok" >
    </Button>

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Cancel" >
    </Button>

</LinearLayout>

4.That's it now you can easily display popup window in your application.

The full source code is here

Beginners in Android

Beginner in Android? Develop Application now


1.Required Softwares for Android Application Development
      if u don't have jre7 or java then download here.
      To set the path of java right-click on My computer-->Advance System Setting-->
      in the Advance tab click on Environment Variable.
      In system Variable edit path and give your java path.
      ex:- ;C:\Program Files\Java\jdk1.7.0_25\bin
      That's all. The Process is shown below.






Now Extract the ADT bundle downloaded.
open Eclipse-->eclipse.exe.








Now to run the Application We need a Android Device.
So lets Create one Android Virtual Device(AVD).



Now lets run our Application.


Wait till the android device launces.



That's it.

Wednesday 25 September 2013

Animations in Android

How to apply animations for the objects in android??


This are few animation xml files which should be stored in res/anim folder.

alpha.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha 
android:fromAlpha="0" 
android:toAlpha="1.0"
android:fillAfter="true" 
android:duration="7000"
/>
</set>

rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
    android:fromDegrees="0"
    android:toDegrees="-360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="7000"
    />
</set>

scale.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:duration="2500"
/>
</set>

spin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <rotate  
       android:fromDegrees="0"
       android:toDegrees="360" 
       android:duration="2000"
       android:pivotX="50%" 
       android:pivotY="50%" 
       android:repeatCount="infinite"
  />  
</set>

translate.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate  
android:fromXDelta="110" 
android:toXDelta="-120" 
android:duration="4000" 
android:fillAfter="true"
  android:fromYDelta="190" 
  android:toYDelta="0"
/>
</set>


All the above xml files should be stored in res/anim folder

Next now in
MainActivity.java

package com.sri.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView;
import android.widget.Spinner;

public class MainActivity extends Activity implements OnItemSelectedListener {
Spinner sp;
ImageView i;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = (Spinner) findViewById(R.id.spinner1);
i = (ImageView) findViewById(R.id.imageView1);
sp.setOnItemSelectedListener(this);
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long item) {
// TODO Auto-generated method stub
if (item == 1) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
i.startAnimation(a);
}
if (item == 2) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.rotate);
i.startAnimation(a);
}
if (item == 3) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.scale);
i.startAnimation(a);
}
if (item == 4) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.spin);
i.startAnimation(a);
}
if (item == 5) {
Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
i.startAnimation(a);
}

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/Animation" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_marginTop="100dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/facebook" />

</LinearLayout>

values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Animation</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>

    <string-array name="Animation">
        <item>Select Item</item>
        <item>Alpha</item>
        <item>Rotate</item>
        <item>Scale</item>
        <item>Spin</item>
        <item>Translate</item>
    </string-array>

</resources>

Now run the application.

Thursday 19 September 2013

WebView in Android

Using a web view to load a page from Internet


WebView is nothing but the simple view created within the application so as to load the web pages within the application and not exit the application and load in the inbuilt browser.

1.MainActivity.java

package com.sri.webview;

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

public class MainActivity extends Activity {
WebView wb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wb=(WebView) findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl("http://www.google.co.in");
}
}


2.activity_main.xml

<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" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

3.Add permission in the android manifest file

<uses-permission android:name="android.permission.INTERNET"/>

4.That's it

Tuesday 17 September 2013

Gallery View using Gesture Detector on touch event

Implementing gallery view for touch event using gesture detector and gesture listener.


In all Application development you compulsory need a gallery view. And for smart Phone you need touch gallery change image. so here is an best example to implement the gallery view.

Copy the code in your code.

1.MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnTouchListener {

ImageView im;
int i = 0;
int images[] = { R.drawable.img1, R.drawable.img2, R.drawable.img3,
R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7,
R.drawable.img8, R.drawable.img9 };
private final GestureDetector gestureDetector = new GestureDetector(
new GestureListener());

public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
im = (ImageView) findViewById(R.id.image_place_holder);
im.setOnTouchListener(this);
}

private final class GestureListener extends SimpleOnGestureListener {

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD
&& Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
i--;
if (i < 0)
i = images.length;
im.setImageResource(images[i]);
} else {
i++;
if (i > images.length)
i = 0;
im.setImageResource(images[i]);
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
}

2. activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/id1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/image_place_holder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="10dip"
        android:gravity="center" 
        android:src="@drawable/img1"/>

</LinearLayout>

3.save all your images in drawables, and edit the names in MainActivity.java in int images[];

4. That's it.

Thank you 

Monday 16 September 2013

Seek Bar with progress showing with two text views

Seek Bar with progress showing with two text views


In the previous Post i told you how to add the seek bar for media player. Now i'll tell you to add two text views to media player which shows the progress of the seek bar.

1.activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp" />

        <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/seekBar1"
        android:layout_marginBottom="40dp"
        android:layout_marginRight="26dp"
        android:layout_toLeftOf="@+id/textView2"
        android:text="Stop" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button2"
        android:layout_alignBottom="@+id/button2"
        android:layout_toRightOf="@+id/textView1"
        android:text="Play" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/seekBar1"
        android:layout_alignRight="@+id/seekBar1"
        android:layout_marginRight="15dp"
        android:text="0:00" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/seekBar1"
        android:layout_marginLeft="16dp"
        android:text="0:00" />

</RelativeLayout>

2.MainActivity.java

package com.sri.seekbar;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements Runnable,
OnClickListener, OnSeekBarChangeListener {
private SeekBar seekBar;
private Button startMedia;
private Button stopMedia;
private MediaPlayer mp;
TextView tv1, tv2;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
startMedia = (Button) findViewById(R.id.button1);
stopMedia = (Button) findViewById(R.id.button2);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
startMedia.setOnClickListener(this);
stopMedia.setOnClickListener(this);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setEnabled(false);
}

public void run() {
int currentPosition = mp.getCurrentPosition();
int total = mp.getDuration();

while (mp != null && currentPosition < total) {
try {
Thread.sleep(1000);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
seekBar.setProgress(currentPosition);
}
}

public void onClick(View v) {
if (v.equals(startMedia)) {
if (mp == null) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.song2);
seekBar.setEnabled(true);
}
if (mp.isPlaying()) {
mp.pause();
startMedia.setText("play");
} else {
mp.start();
startMedia.setText("pause");
seekBar.setMax(mp.getDuration());
new Thread(this).start();
}
}

if (v.equals(stopMedia) && mp != null) {
if (mp.isPlaying() || mp.getDuration() > 0) {
mp.stop();
mp = null;
startMedia.setText("play");
seekBar.setProgress(0);
tv1.setText("0:00");
tv2.setText("0:00");
}
}

}

public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
if (mp.isPlaying() || mp != null) {
if (fromUser)
mp.seekTo(progress);
} else if (mp == null) {
Toast.makeText(getApplicationContext(), "Media is not running",
Toast.LENGTH_SHORT).show();
seekBar.setProgress(0);

}
tv1.setText("" + milliSecondsToTimer(progress));
tv2.setText("" + milliSecondsToTimer(mp.getDuration()));
} catch (Exception e) {
Log.e("seek bar", "" + e);
seekBar.setEnabled(false);

}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

public String milliSecondsToTimer(long milliseconds) {
String finalTimerString = "";
String secondsString = "";

// Convert total duration into time
int hours = (int) (milliseconds / (1000 * 60 * 60));
int minutes = (int) (milliseconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliseconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
// Add hours if there
if (hours > 0) {
finalTimerString = hours + ":";
}

// Prepending 0 to seconds if it is one digit
if (seconds < 10) {
secondsString = "0" + seconds;
} else {
secondsString = "" + seconds;
}

finalTimerString = finalTimerString + minutes + ":" + secondsString;

// return timer string
return finalTimerString;
}
}

3.That's it  now run your Project and see the text view changes with the progress bar.
Thank you