Notepad Android Development

broken image


Introduction:

  • The notepad consists of three options to create new file, save and open a file. When you click on save or open button an alert dialog opens where you have to enter the file name. Internal memory is used to save the text file.
  • Android Open Source - App/notepad. App; Sketch-Notes a sketching notepad android app Score:12 Activity:3 Min SDK:8 Target SDK:12 Java File:6 Manifest File:1; MoneyTracker A simple money tracker app for Android. Loosely based on the Notepad Android example. Score:9 Activity:2 Min SDK:3 Java File:9 Manifest File:1; notes Note Now - notepad for Android Score:7 Fragment:3 Activity:4 Java.
  • May 24, 2017 To do this, just open up Android Studio and then select New New Project. Choose ‘Basic Activity' (the one with the Floating Action Button) and then you should be good to go!

How to create simple notepad android app using android studio with validation This tutorial in on how to create a simple (notepoint)notepad android app using android studio with validation. A simple notepad that support Select All/ Copy/ Font size/ Font style and New document. Missing operation & features coming next version. Notepoint project is a android app is implemented in android studio.

We assume that the readers of this tutorial have got basic knowledge about relational databases and SQL.

We will start from the basics and incorporate some functionalities step by step. Here we are going to create a very simple database that will serve us as data storage for our app.

At the end of this tutorial you will know how to:

  • create a simple SQLite database in Android.
  • get access to SQLite database via the command prompt (terminal) and execute some simple queries.

Facts about SQLite database

Facts about SQLite:

  • SQLite is free and open-source embedded SQL database engine.
  • SQLite reads and writes directly to ordinary disk files.
  • A complete SQL database is contained in a single disk file.
  • The database file format is cross-platform.
  • It supports standard relational database features including syntax, transactions and prepared statements. Transactions are ACID.

Database Structure

Our database will contain only one table and the following columns to persist notes:

  • title -- text (note title)
  • body -- text (note body text)
  • _id -- integer, autoincrement (the id of the note)

Creating the Database

Get Best Notepad++ For Android APK Download Online [Latest ..

Let's create a new project with default settings which contain a single activity called NotesListActivity. Now, in the same package with our activity, create a class called NotesDbAdapter. This class will contain SQLiteOpenHelper as a subclass which is a class to manage database creation and versioning. NotesDbAdapter will grant us an access to our database by defining CRUD methods . So let's create the wrapper class for our database and define all the constants we need and static inner class to get a database connection.

Listing1: Defining NotesDbAdapter.java

The code looks quite big but actually there is nothing special here. We create static subclass ofSQLiteOpenHelper and implement abstract methods onCreate() and onUpgrade(). The onCreate() method is invoked when there is no database available for our app, so in this method we have to execute all the statements to create our database. onUpgrade() is invoked when the version of the current database is smaller than new version (database version is provided when SQLiteOpenHelper subclass instance is created and this version is passed as a parameter to a superclass constructor).

Notepad Android Development

Notepad Android Development

NotesDbAdapter is a wrapper class that holds the instance of SQLiteOpenHelper and provides API for database access. Now we need to create an instance of our NotesDbAdapter in our activity by calling the open() method to create the database. That's all the code we need to have a working database.

Listing2: Defining NotesListActivity.java

Accessing SQLite Database from ADB Shell

Now we need to make sure that our database is created and in a working state. Let's open DDMS perspective in Eclipse (or launch monitor from tools folder in your SDK location) and locate the database file on the device file system.

Emulator/device instances store SQLite3 databases in the folder:

/data/data//databases/

To issue SQL queries to your database enter a remote shell on the emulator instance and enter sqlite3command following with the full path to our database. Here is an example:

Listing3: Entering a remote shell on the emulator

In Windows, to acces ADB directly from command prompt add path of your SDK to your environment variables. In Mac OS, follow the below instructions:

If you have only one USB device or emulator connected you don't need to specify what device is the target for your commands. Otherwise you need to direct your commands to the targeted device by specifying arguments after adb command.

Listing4: Using the adb command

Now you can execute your SQL queries directly to your database. Let's insert a few rows into our database and then query all of them.

Listing5: Executing SQL queries

As you can see, everything is great.Our database is fine and ready to use. The first step now is to import the Notepad_Start project into Eclipse. To do this, create a new Android project in Eclipse, and then select Create project from existing source in the New Android Project dialog box.

The Notepad_Start project is the starting point of our tutorial and this is a modified version of Notepad tutorial.

Right-Click the Notepad_Start project in eclipse and click Properties. This brings up the Properties dialog box. Click Android in the left pane to bring up the Project build target list. Check that Android 3.0 ( or higher) is available as one of the targets. If it is not, please bring up the Android SDK and AVD Manager and follow the steps outlined at Installing Android sdk to install Android 3.0, API Level 11. Once the target Android 3.0 has been installed, change the Build Target to Android 3.0, API Level 11.

Listing6: Specify the android:minSdkVersion as 7 and android:targetSdkVersion as 11.

For SDK Level 7 add the following style definition to the file res/values/styles.xml. We are extending Theme.Light

Listing7: Extending Theme.light

Turn on the hardware acceleration by specifying android:hardwareAccelerated='true' in the AndroidManifest.xml file.

Listing8: Specifying android: hardwareAccelerated='true'

The next step is to create a new Activity to host Fragments. Right-click on the src folder in Package Explorer and click on New --> class: In the 'New Java Class' window which comes up add the class name as NotepadActivity in the package com.example.android.Notepad . Add the super class as android.support.v4.app.FragmentActivity and click FINISH.

Open layout file res--> layout--> notepad.xml, this will be the layout for this activity. It uses a container to host the fragments @+id/list.

Listing9: Layout for the activity

Override onCreate(.) method of NotepadActivity and set the notepad.xml as the content view.

Listing10: Defining Overide onCreate(.) method

The last step is to add Action Item to the Action Bar. In this step we will add an action item AddNote to the Options Menu in the Action Bar.

Override onCreateOptionsMenu in NotepadActivity class. Populate it using the MenuInflater from R.menu.notepad_menu resource file defined in res/menu/notepad_menu.xml file.

Shortcut key to screenshot. Listing11: Defining Override onCreateOptionsMenu

Listing12: Code showing the contents of res/menu/notepad_menu.xml file

Sample Output:


Figure 1: Notepad in Android Device

Conclusion

We learned how to create notepad application for Android devices explaining from scratch how to create a database and then use it to develop notepad.





broken image