Answer the question
In order to leave comments, you need to log in
How to create file not in onCreate method?
Write file creation and writing / reading in a separate class and call it in the button event handler. It works if you just write directly to the method. But how to put everything in a class and call a couple of methods from it in onCreate? Gives an error message :(
public class Own extends AppCompatActivity {
TextView textView;
Button button;
private static final String LOG_TAG = "my_tag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_own);
textView = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
FileWorker fileWorker = new FileWorker();
fileWorker.fileProcess();
textView.setText("Выполнено");
}
});
public class FileWorker extends Own {
private static final String LOG_TAG = "my_tag";
String string;
FileWorker(){
string = "hi";
}
void fileProcess() {
File file = new File("myFile.txt");
if(file.exists()) {
Log.d(LOG_TAG, "Файл существует!");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question