Hi dharmendr sir,
I have a button showing text START when I click on it I shows me current time in textview. (I consider this time as start time).
Than convert the text on Button into STOP. When I click on it again show me current time on another textview (I consider this time as stop time).
And then calculate the difference between these two times.
I want this same working for multiple times.
I mean First button show Text ENTERS. When I click on it should show current time in textview. (I will consider this time as Enter time).
Than convert the text on Button into START. When I click on it again show me current time on another textview (I will consider this time as start time).
Than convert the text on Button into STOP. When I click on it again show me current time on another textview (I will consider this time as STOP time).
And last
Than convert the text on Button into EXIT. When I click on it again show me current time on another textview (I will consider this time as Exit time).
Here is my code in java language.
Please help me sir please.
btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isStarted){
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss aa");
String time = format.format(calendar.getTime());
tvend.setText(time);
try {
Date date1 = format.parse(tvend.getText().toString());
Date date2 = format.parse(tvstarttime.getText().toString());
long mills = date1.getTime() - date2.getTime();
Log.v("Data1", ""+date1.getTime());
Log.v("Data2", ""+date2.getTime());
int hours = (int) (mills/(1000 * 60 * 60));
int mins = (int) (mills % (1000*60*60));
String diff = hours + ":" + mins;
diffence.setText(diff);
} catch (ParseException e) {
e.printStackTrace();
}
btn_start.setText("START");
}else {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss aa");
String time1 = format.format(calendar.getTime());
tvstarttime.setText(time1);
btn_start.setText("STOP");
}
isStarted = !isStarted;
}
});