Hi guys,
I'm new to Android dev. and probably this question might be silly but
I haven't find a good answer by googling the web. I want to display a
chronometer and two buttons (Start and Stop) in a LinearLayout view.
Is it possible to specify a format different from "0:00"? I want to
have a format similar to "0:00:00.0" (like format available on
iPhone). Using setFormat does change the format, but I'm suspecting
it's not the right way to proceed: infact you can insert what string
you want (even a name...) and the system will display it, but of
course clicking start or stop won't produce any effect on it.
I've posted the source code.. can you help me? Thanks!!


main.xml:

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

<Chronometer android:layout_height="wrap_content" android:id="@+id/
chronometer" android:text="Chronometer"
android:layout_width="fill_parent" android:textSize="32sp"
android:gravity="center_horizontal" android:format="0:00:00.000"></
Chronometer>
<Button android:text="Start" android:id="@+id/startButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<Button android:text="Stop" android:id="@+id/stopButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>


class com.example.helloandroid.HelloAndroid.java

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;

public class HelloAndroid extends Activity {
        private boolean started = false;


   /** Called when the activity is first created. */
   @Override
  public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       this.setContentView(R.layout.main);
       final Chronometer chronometer = (Chronometer) this.findViewById
(R.id.chronometer);

       Log.d("HelloAndroid", "Value of getFormat() is: "+
(chronometer.getFormat()));



       final Button startButton = (Button) findViewById
(R.id.startButton);
       startButton.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
                   if(!started){
                           Log.d("Hello Android", "start button clicked");
                           started = true;

                           chronometer.start();
                   }
           }
       });


       final Button stopButton = (Button) findViewById
(R.id.stopButton);
       stopButton.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
                   if(started){
                           Log.d("Hello Android", "stop button clicked");
                           started = false;
                           chronometer.stop();
                   }
           }
       });
   }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to