So I have this project that I need to make as soon as I can and because of that I don't have much time to solve this myself.
I have two buttons: "Start" and "Stop", and I need my program to make a new date when I press "Start" and when I press "Stop" I need to make another date and to display both dates.
My problem is that, when I want to display both dates on press of the "Stop" button, the date that was created in the first button press does not exist.
I used setOnClickListener function for detecting the press of both my buttons.
public class MainActivity extends AppCompatActivity {
private Button mStartButton;
private Button mStopButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStartButton = (Button) findViewById(R. id. button_start);
mStopButton = (Button) findViewById(R. id. button_stop);
mStopButton.setClickable(false);
mStartButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v ) {
//start stoperica
final Date datumpocetak = new Date();
mStartButton.setClickable(false);
mStopButton.setClickable(true);
}
});
mStopButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v ) {
//stop stoperica
TextView display = (TextView)findViewById(R. id. display);
Date datumkraj = new Date();
String rezultat = new String();
rezultat = ("od" + (datumpocetak) "do" + (datumkraj));
}
});
}
}