Simple notepad implementation and analysis (3) Main Interface

Source: Internet
Author: User

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

 

...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.