android


How to display recording time in Android?


I developed a sound record application for Android that is working fine. Now I want to display the recording time in a TextView. How can I implement it?
Use CountDownTimer Because when you record at that time may be TimerTask not work , as per my knowledge
CountDownTimer t;
t = new CountDownTimer( Long.MAX_VALUE , 1000) {
#Override
public void onTick(long millisUntilFinished) {
cnt++;
String time = new Integer(cnt).toString();
long millis = cnt;
int seconds = (int) (millis / 60);
int minutes = seconds / 60;
seconds = seconds % 60;
txtcount.setText(String.format("%d:%02d:%02d", minutes, seconds,millis));
}
#Override
public void onFinish() { }
};
Start timer t.start();
Stop timer t.cancel();
When you start recording start the timer
Here is the code
int minute =0, seconds = 0, hour = 0;
textView = (TextView) view.findViewById(R.id.textView1);
final Timer t = new Timer("hello", true);
t.schedule(new TimerTask() {
#Override
public void run() {
textView.post(new Runnable() {
public void run() {
seconds++;
if (seconds == 60) {
seconds = 0;
minute++;
}
if (minute == 60) {
minute = 0;
hour++;
}
textView.setText(""
+ (hour > 9 ? hour : ("0" + hour)) + " : "
+ (minute > 9 ? minute : ("0" + minute))
+ " : "
+ (seconds > 9 ? seconds : "0" + seconds));
}
});
}
}, 1000, 1000);
view.findViewById(R.id.stop).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
t.cancel();
}
});
You can use Timer and TimerTask in android.
check here ...http://android.okhelp.cz/timer-task-timertask-run-cancel-android-example/
Use android.widget.Chronometer to record time.
See com.example.android.apis.view.ChronometerDemo in ApiDemos for usage.

Related Links

AppCombat v21 TextAppearance on Gingerbread with DarkActionBar
Will I use more battery if I set a repeating alarm for every 10 minutes from now on instead of setting a new single alarm each time?
SQLite snippet function implementation does not format Text as HTML in TextView
Show and hide Action bar while scrolling view pager content
Port Absolute Layout to Relative Layout
ListView onItemClickListener is returning wrong position after animation
How to update my app in Eclipse
Adding BaseGameUtils to Android Studio
Chrome (WebKit) ng-model issues with select display value
Youtube player crashes with giving java.lang.IllegalStateException: android.os.DeadObjectException in Android
How to set a listener in a RadioButton - Android
App Widget: can you specify a minimum AND a default size?
AES encryption between Android and Arduino
Call new request only if response of previous request returns from server
Prevent “ACTION_CHANGE_DEFAULT” from prompting automatically to change default SMS app
Debugging Android over WiFi without first authorizing over USB?

Categories

HOME
shell
cygwin
xml
kentico
fftw
jwplayer
permissions
onclick
mautic
line
parameter-passing
package-managers
vuejs
wolframalpha
cfml
solrcloud
roslyn
expressionengine3
android-maps
subclass
user-defined-functions
jaws
panoramas
eviews
mustache
r-grid
catch-unit-test
code-snippets
android-maps-extensions
fossil
hibernate-search
processwire
hivemq
xv6
postgresql-8.4
linqpad
microsoft-metro
chronicle-map
avcapturedevice
wc
facebook-social-plugins
jide
pom.xml
nanoc
ntvs
opennms
dtsearch
git-flow
quicktime
lsyncd
rxtx
myspace
rspec2
delta
dimension
swizzling
android-wake-lock
nservicebus5
np-spring
rasterize
grgit
r-package
fiware-monitoring
ons-api
sony-lifelog-api
ember-cli-rails
graphics2d
pyobjc
uvc
public-html
formview
windows-embedded-standard
notorm
composite-component
windows-98
device-width
extreme-programming
saleslogix
jquery-address
ikimagebrowserview
xcelsius
strsep
uideviceorientation
folding
purepdf
asynchronous-wcf-call
product-management
image-capture

Resources

Encrypt Message