Xamarin.android Notepad (i)

Source: Internet
Author: User

Guide

1. Creation of views and databases

2.listview Data Binding

3.listview of Click events

Body

How to create a ListView, you can see here, the basic process operation is the same, I will not say, and then is a new database, the code is as follows

classSqlite:sqliteopenhelper { PublicSqlite (Context context):Base(Context,"notebooksql.db",NULL,1)        { }         Public Override voidOnCreate (Sqlitedatabase db) {db. Execsql ("CREATE TABLE notebooksql (_id INTEGER PRIMARY KEY autoincrement not null,title text not null,context text not Null,ti Me time not NULL)"); Db. Execsql ("INSERT into Notebooksql (title,context,time) VALUES (' This is the first note ', ' notes notes ' first note Note Note Notes First notes Note Notes first notes note notes first notes ', ' 2015-3-15 ')"); Db. Execsql ("INSERT into Notebooksql (title,context,time) VALUES (' This is the second note ', ' note Note ' Second Note Note Note Notes Second Note Note Note Second Note Note notes ', ' 2015-3-15 ')"); }         Public Override voidOnupgrade (Sqlitedatabase db,intOldversion,intnewversion) {db. Execsql ("DROP TABLE IF EXISTS notebooksql");        OnCreate (DB); }    }

This sets up a self-increment primary key and three fields, and then I add two default data.

After the database is created we open Activity1, inherit listactivity, bind the data to the ListView

 protected Override voidOnCreate (Bundle bundle) {Base.            OnCreate (bundle); VDB=NewSqlite ( This); Cursor= Vdb. Readabledatabase.rawquery ("SELECT * from Notebooksql",NULL);            Startmanagingcursor (cursor); string[] title =New string[] {the title"," Time" }; int[] Time =New int[] {Resource.Id.textView1, Resource.Id.textView2}; ListAdapter=NewSimplecursoradapter ( This, Resource.Layout.Item, cursor, title, time); }

Above

With the data of the ListView but can not operate there is no effect, we can re-Onlistitemclick method to add click events to the ListView

protected Override voidOnlistitemclick (ListView L, View V,intPositionLongID) {stringTitle= v.findviewbyid<textview>(Resource.Id.textView1).            Text.tostring (); stringTime = v.findviewbyid<textview>(RESOURCE.ID.TEXTVIEW2).            Text.tostring (); VDB=NewSqlite ( This); Cursor= Vdb. Readabledatabase.rawquery ("SELECT * from Notebooksql where title= '"+ title+"' and time = '"+ Time +"'",NULL); Cursor.            Movetofirst (); stringNid = cursor. GetString (cursor. Getcolumnindex ("_id")); varIntent =NewIntent ( This,typeof(Note)); Intent. PutExtra ("ID", Nid);            StartActivity (Intent);  This.        Finish (); }

This is convenient for the diagram, I get the ID directly according to title and time.

As follows

Xamarin.android Notepad (i)

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.