I. Overall code structure of notepadv3
With the preceding helper class, you can directly call it on the main interface. notepadv3 inherits the main code of the listactivity class. For the implementation of each function, see the source code. (Source Code connection)
public class Notepadv3 extends ListActivity
{
private static final int ACTIVITY_CREATE = 0;
private static final int ACTIVITY_EDIT = 1;
private static final int INSERT_ID = Menu.FIRST;
private static final int DELETE_ID = Menu.FIRST + 1;
private NotesDbAdapter mDbHelper;
public void onCreate(Bundle savedInstanceState)
private void fillData()
public boolean onCreateOptionsMenu(Menu menu)
public boolean onMenuItemSelected(int featureId, MenuItem item)
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
public boolean onContextItemSelected(MenuItem item)
private void createNote()
protected void onListItemClick(ListView l, View v, int position, long id)
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
}
Ii. Function Analysis
Here, we only analyze some functions, so the menu-related functions are no longer mentioned.
1. do two things in oncreate (bundle savedinstancestate), call the filldata function () to display the record on the initialization interface, and register the context menu button.
2. filldata (), custom function: retrieve all records from the database and display them to the items in the list:
Private void filldata ()
{
// Obtain all row records from the database and create an item set to store them
Cursor notescursor = mdbhelper. fetchallnotes ();
Startmanagingcursor (notescursor );
// Extract the title of each record from the set and put it into a String Array
String [] From = new string [] {notesdbadapter. key_title, notesdbadapter. key_body };
// Bind the layout textview of the corresponding data display, which is located in the separate notes_row.xml
Int [] to = new int [] {R. Id. text1, R. Id. Content };
// Create simplecursoradapter and bind it to the appearance XML file. parameters correspond to data and specific layout respectively.
Simplecursoradapter notes = new simplecursoradapter (this, R. layout. notes_row, notescursor, from, );
Setlistadapter (notes );
}
Create record createnote (), call noteedit through intent, and create a record on the new page.
private void createNote()
{
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
III,
All the coding work has been completed. It is worth mentioning that the use of the draw9patch tool is not used in the official notepad case, but this tool is very good. Although it seems useless after use, there are already garden friends in the garden who have scanned it in detail and will not go into details.
Source code connection
...