我想将android studio天文钟的时间保存在可在应用程序内部访问的txt文件中。 (例如,单击“保存”按钮,天文钟表的值将保存在txt文件中(以后可访问))
代码中的
BTW,如果可能的话,它还具有一个内置计数器,可以将allong与txt文件保存在一起,而该文件将是AWESOME。只是不确定如何做
这里是我的代码MainActivity.java
public class MainActivity extends AppCompatActivity {
private Chronometer chronometer;
private long pauseOffset;
private boolean running;
private int mCounter = 0;
private Button button;
Button btn;
TextView txv;
TextView txtv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chronometer = findViewById(R.id.chronometer);
btn = (Button) findViewById(R.id.bt);
txv = (TextView) findViewById(R.id.tx);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCounter++;
txv.setText(Integer.toString(mCounter));
button = (Button) findViewById(R.id.PreviousRuns);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openRunHistory();
}
});
}
});
}
public void startChronometer(View v) {
if (!running) {
chronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
chronometer.start();
running = true;
}
}
public void pauseChronometer(View v) {
if (running) {
chronometer.stop();
pauseOffset = SystemClock.elapsedRealtime() - chronometer.getBase();
running = false;
}
}
public void resetChronometer(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
txv.setText("0");
mCounter = 0;
txtv.setText("");
}
public void openRunHistory() {
Intent intent = new Intent(this, RunHistory.class);
startActivity(intent);
}
答案 0 :(得分:0)
这是您必须在onClick的保存按钮上实现的代码,“ data”是带有时间的字符串
SetConsoleCP
}