Reputation: 426
I need to toast the stopwatch's value
ie.,time taken between start and stop
If i click the stop button it should toast that time duration. How to do this?
Here i have tried some code
chrono_meter.java
public class Chrono_meter extends Activity {
Chronometer chr;
Button btn_stop_travel;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chronometer_layout);
chr = (Chronometer)findViewById(R.id.chronometer1);
chr.start();
btn_stop_travel = (Button)findViewById(R.id.btn_stop_inspection);
btn_stop_travel.setOnClickListener(mStopListener);
}
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
}
};
}
Upvotes: 0
Views: 229
Reputation: 9035
Try this
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
Toast.makeText(Chrono_meter.this, chr.getText(), Toast.LENGTH_LONG).show() ;
}
};
Upvotes: 1