I programmed a stopwatch but it works with java, but not on Android. If I press the Button it makes nothing. Could it be, that maybe Eclipse is wrong installed?
package com.example.stoppuhr;
import java.text.SimpleDateFormat;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
long start;
long millis;
public void onClick(View v) {
Button start1 = (Button)findViewById(R.id.button1);
Button button2 = (Button)findViewById(R.id.button2);
TextView textView1 = (TextView)findViewById(R.id.textView1);
start1.setOnClickListener(this);
I think here is the problem.
if (v.getId() == start1.getId()){
textView1.setText("moldu");
start = System.currentTimeMillis();
while (true){
millis = System.currentTimeMillis()-start;
SimpleDateFormat sdfDate = new SimpleDateFormat("mm:ss.SSS");//dd/MM/yyyy
String ausgeben = sdfDate.format(millis);
textView1.setText(ausgeben);
try {
Thread.sleep(30);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
Thank you for your help