
The File that we have been talking about will be a. If the file doesn’t exist, writeToFile() also creates the file in the memory. Now, we’ll define two methods to read and write data to files: readFromFile() and writeToFile().Īs the name suggests, readFromFile() will be used to read the data from the file, and writeToFile() will be used to write to the file.
#Code scratchpad how to#
How to handle file input and output operations in Android
#Code scratchpad code#
Remember the IDs we had assigned to the widgets in the XML file? They are used here, to connect the Java code to the XML code components. Write this below setContentView(R.layout.activity_main) inside onCreate() function. Now we’ll reference the actual widgets from the XML file. If you gave it a name other than MainActivity, that will be the main function: private EditText todoText Write the following code inside the main function before the onCreate() function. Let’s start adding our widgets to the code. Now we’ll get down to the actual coding part. Coding the actual functionality of our Scratchpad app Replace the default code with the following: The end result of the above few lines of code will look like this: This is what the app would look like Changing the colours of the AppĪdditionally, let’s change the colours to the app, these will be visible on the title bar when we run the app, and when the EditText is selected. We have set the inputType attribute of the EditText to ‘textMultiLine’ this will allow the user to input multiple lines of text.

EditText allows the user to enter text input it could be anything – email, password, numeric input etc.īutton provides a clickable interface for performing certain actions. We’ve added two widgets: EditText and Button.

Now, for the Button, add the following code right after the EditText code.: Ideally, it should be big and have lots of space since it is the main part of our app. I’ll be illustrating the code part of it since it is easy to explain in a textual tutorial.įirst, the EditText. Android Studio provides an intuitive drag and drop interface to design app visuals.

As you might have observed earlier, the designing part of an activity is done using XML. Let’s move forward to the designing part. In this app, we’ll be working with a single activity. Java File Building the interface of the scratchpad app in Android.How to view the contents of a private.How to handle file input and output operations in Android.Coding the actual functionality of our Scratchpad app.Building the interface of the scratchpad app in Android.
