Simple Notepad for Android

This example shares the specific code of Android simple Notepad for your reference. The specific contents are as follows

The storage method of Android simple Notepad this time uses SQLite database, and the implementation of the interface is relatively simple. However, it has the basic function of adding, deleting, modifying and querying. Here you can see the effect diagram as follows:

The specific operation is to long press to delete, click to modify, and click the add note button to add a note.

First, we need three interface styles. One is the first interface when we enter the program, and then there is a listview in the first interface. This listview needs an XML to describe each element in it, which is also the second. Another is the interface of our editing page. The three XML description files are as follows:

activity_ Main.xml: enter the first interface of the program

note_ Item.xml: describes the controls for each element in the Notepad list

note_ Editor.xml: editing interface

Now we can consider the operation of our underlying database. Here is a class dedicated to dealing with the database, as follows: dbservice.java

Next, when we enter the first interface, we need to access the database and constantly update the data values (for example, we need to refresh when deleting or after adding). In this way, we may need to rewrite onresume() of activity, so that we can call requery() of cursor to refresh the results of listview in our list. In addition, we need to long press Delete, click Modify and add notes, which all need to listen to events. Therefore, we also need to set the listening code of mainactivity.java as follows:

The above code also involves the operation of passing information after a view switch, which is called getIntent ().Get~Extra (key, replace) in the view after handover through putExtra (key, value) of Intent. To receive the transmitted data.

The following is the corresponding implementation code in our editing interface. Here we judge whether to use the update operation or add operation, mainly to judge whether mainactivity.java has passed the ID. if yes, it is through this ID to update the operation, and if not, it is an add operation.

The specific implementation code corresponding to the editing interface is as follows:

NoteEditActivity.java

The above completes our Android simple Notepad, and the source code has been uploaded to GitHub.

The interface adopts the take doctrine. You can refer to the following articles

Android implements Notepad app

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>