- Android studio (prefereably latest version) IntelIJ platform
- Any android device (for testing)
- Intel core processor
- 4GB RAM
- 1GB memory space (for studio)
Generating the application:
Install Android Studio and open it. Start a New project and name the app. Choose blank activity for the basic layout and hit finish button. Android studio will generate the basic app project framework.
Since it is a notepad app, focus has to be given for adding each activity as the user clicks the plus button i.e, adding a new note. For this a separate file named NoteActivity.java has to be created for controlling each note.
Go to app folder->java->file with app name-> right click->new->activity->empty activity->name the new java file -> finish. Add the following code:
Inorder to view the saved notes in a list view, we should change the RelativeLayout of MainActivity to ListView layout. This is changed in the content_main.xml by adding the code below.
The aesthetic part of the app and UI are controlled by XML files. MainActivity has two xml files ; activity_main.xml and activity_note.xml.
A template layout is only provided by the Android development libraries. This item defines the styles used to render out ListView on screen. It is an XML file which contains one item.
To define the item as a list, simply right click the simple_list_item1 text in the MainActivity.java file and a menu will appear. Select GoTo, select the declaration menu item and Android Studio will open up that layout (XML) file for you. This is basic style for a simple list view. The screen shown below will be created as soon as you create it.
Another XML file called string.xml file is required for the functioning of pop-up messages on button clicks and other strings used in the app.It is a resource file.
All these XML files and the NoteActivity.java has to be now incorporated into MainActivity.java to include all the functionalities of each xml files and java class into the application.
Saving the notes:
Once UI is done we need to save the notes created by the user upon clicking the “Save” button. The code for adding this functionality is as follows:
After filling all this code, go ahead and compile the code. Debug all the errors and after the build is finished run the generated app on an emulator or any android device with the help of ADB (Android Device Bridge).
Final app will look like this:
Hope you'll try this out!
Subscribe to Code Rewritten
Get the latest posts delivered right to your inbox