Déclarer deux chronomètres
bonjour ,
Je veux 2 chrono identique l'un sous l'autre .
Je veux que le start démarre les 2 chrono1 / 2
Et stop 1 / 2 arrête l'un après l'autre
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| package com.example.chrono;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
public class MainActivity extends Activity {
private static final OnClickListener StartListener = null;
//On déclare toutes les variables dont on aura besoin
Button start;
Button reset;
Button stop1;
Button stop2;
Chronometer Chrono1;
Chronometer Chrono2;
boolean firstStart = true;
private OnClickListener startListener2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//On récupère tous les éléments de notre interface graphique grâce aux ID
// ******** DEFINITION DES CONSTANTES ET VARIABLES ********************
start = (Button) findViewById(R.id.button1);
start.setOnClickListener(StartListener);
stop1 = (Button) findViewById(R.id.button2);
reset = (Button) findViewById(R.id.button3);
stop2 = (Button) findViewById(R.id.button4);
Chrono1 = (Chronometer) findViewById(R.id.chronometer1);
Chrono2 = (Chronometer) findViewById(R.id.chronometer2);
startListener2 = new View.OnClickListener() {
public void onClick(View v) {
if (firstStart){
Chrono1.setBase(SystemClock.elapsedRealtime());
//Chrono2.setBase(SystemClock.elapsedRealtime());
firstStart = false;
}
Chrono1.start();
//Chrono2.start();
}
};
}} |
Le start ne démarre rien ..
Pouvez vous donner un avis de correction ?
@+
-----------------
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="${relativePackage}.${activityClass}" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1"
android:layout_marginLeft="57dp"
android:layout_marginTop="30dp"
android:text="@string/chronometer"
android:textSize="80dp" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/chronometer1"
android:layout_marginLeft="33dp"
android:layout_toRightOf="@+id/chronometer1"
android:minWidth="78dip"
android:text="@string/reset" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/chronometer1"
android:layout_alignLeft="@+id/button3"
android:layout_marginBottom="16dp"
android:maxWidth="38dip"
android:minWidth="78dip"
android:text="@string/stop1" />
<Chronometer
android:id="@+id/chronometer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/chronometer1"
android:layout_marginTop="23dp"
android:text="@string/chronometer"
android:textSize="80dp" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/chronometer2"
android:layout_alignRight="@+id/button2"
android:layout_marginBottom="14dp"
android:minWidth="78dip"
android:text="@string/stop2" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chronometer1"
android:layout_alignParentTop="true"
android:layout_marginTop="37dp"
android:minWidth="78dip"
android:text="@string/start" />
</RelativeLayout> |