Xamrin developing Android Notes (iii)

Source: Internet
Author: User

    • Mounting pads
    • Xamrin Developing Android Notes (i)
    • Xamrin developing Android Notes (ii)

This time the scroll bar was created, stored, and read with SQLite.

First of all, the scroll bar related, this is a relatively simple point of knowledge.

When there is a screen of things to fill out such as

We all know that if you click on the first text box, an input method will appear. But if there is no scroll bar, you can only rely on the input method of the carriage return one of the downward movement (although the input methods are now with self-closing function), very unfriendly, then you need to scroll bar, look at the layout properties have scroll bar, but the use is not good. Vaguely think of it, Android has a scroll bar control, on the left to find a bit, really found this thing. Such as

But how to use this thing, and another search, originally this thing can be nested outside the layout label, so that the entire layout with scroll bar (this scroll bar is both horizontal and vertical, can be closed by the property).

Set on the outside to find the red line, generated when the error.

Error 3 namespace prefix "Android" is not defined.

The solution is to

Xmlns:android= "Http://schemas.android.com/apk/res/android"

Move to the scroll bar. The meaning of this sentence is to define all the tags inside the tag to perform the Android definition.

This way, the input method can appear when the scroll bar.

Simply put, more properties can be researched on your own.

Now let's talk about local library SQLite

First of all, he and T-SQL syntax a little bit different most similar, the difference after a little bit of saying, one-time full write I also can't remember.

There are a lot of ways to create databases on the web and in books, but none of them are completely right, and the book is more of a rip-off, and a lot of content has been integrated. Even the reference space is different (the syntax of the book seems to be very old syntax), so these content can only be used as clues to reference, and even need to refer to the Java Android Development (layout, please refer directly to Java development method).

So I found a straightforward way to create a local library, and summed up a set of basic principles for creating a local library.

1. Create when you definitely need to use it

2, no need to create when not created

3, if the entire program requires the use of a local library, then the program runs initially created

4, if there is a condition to manually create a good direct development using

Creating and using a database requires a reference

Using Android.Database.Sqlite;

Some books and some on-line materials are quoted as mono, but no longer exist in my version (net4.5).

The code is as follows

Sqlitedatabase Database =NULL;//Define this in the most outer name        /// <summary>        ///Create a database/// </summary>        Private voidCreatedata () {stringStrdataname ="phonebook.db3"; Database= This. Openorcreatedatabase (Strdataname, Filecreationmode.private,NULL); stringStrtable ="CREATE table if not exists book (Name,sex,age,phone)";        Database.execsql (strtable); }    

Define the database connection method at the outermost layer because it will be used (because it is a demo so that the official project must write better than the present)

Define the Create method definition database name, DB3 is the database extension,

The method of Openorcreatedatabase probably means that if this database exists then it is opened otherwise the database is created and is private mode created.

CREATE table if not exists book (name,sex,age,phone) This sentence means that this table is created if it does not exist. MSSQL can not jiangzi write.

The last word means Execute SQL. is not very similar to ADO!

OK, here we do a function to create a database and a table, and then create a database with the OnCreate method call.

There are some ways to use IO to find out if the library exists, the way I created the database path is different from the path created by this method (breakpoint debugging can be seen to see)

Then start doing the Save event for the button as follows code

1Btnseve.click + =Delegate2             {3EditText txtname = findviewbyid<edittext>(Resource.Id.txtName);4EditText txtage = findviewbyid<edittext>(Resource.Id.txtAge);5Radiogroup Rdogsex = findviewbyid<radiogroup>(RESOURCE.ID.RDOGSEX);6RadioButton Rdosex = findviewbyid<radiobutton>(Rdogsex.checkedradiobuttonid);7Contentvalues CV =Newcontentvalues ();8Cv. Put ("name", txtName.Text);9Cv. Put ("Sex", rdosex.text);TenCv. Put (" Age", txtage.text); OneCv. Put ("Phone", txtphone.text); A                 LongA = Database.insert (" Book",NULL, CV); -                 varCalldialog =NewAlertdialog.builder ( This); -Calldialog.setmessage ("saved successfully"); theCalldialog.setneutralbutton ("Determine",Delegate -                 { -                     varUserdetail =NewIntent ( This,typeof(userdetailactivity)); -                     //If the parameter is not written, it is a non-parametric jump +  - startactivity (userdetail); +                 }); A calldialog.show (); at};

Contentvalues CV = new Contentvalues ();

This is similar to the SqlParameter in ADO. The first parameter of a put method is a list, and the second is a value.

Long a = Database.insert ("book", NULL, CV); Inserted into this table (originally wanted to write in detail, helpless English too slag, the middle parameter meaning did not understand).

This performs an insert function, and of course you can use the execsql method to perform an insert with SQL, which is not discussed here.

Jump to another page to do the query, do the query before you open the database. Open the database in a way that opens or creates it.

The query code is as follows

1 vardata = Database.query (" Book",New string[] {"Name,sex,age,phone"},"",NULL,"","","");2              while(data. MoveToNext ())3             {4Lbldetail.text + = data. GetString (0)5+ data. GetString (1)6+ data. GetString (2)7+ data. GetString (3) +"|";8             }9 data. Close ();TenDatabase.close ();

This query code has some Java-like query, query which table, those fields, the following conditions are empty, these conditions have a sort where, etc. (to query the name of the table, the name of the field to be obtained, the Where condition, including the optional positional parameters, to replace the location parameter in the Where condition value, GROUP by condition, having condition. )。

The GetString (Index) inside the loop is the column's position, starting at 0.

Basic to this, next time is almost the GridView aspect related content.

The final prohibition is reproduced. Who can tell me how to add a banned reprint style??

From http://www.cnblogs.com/minCS/p/4118170.html

Xamrin developing Android Notes (iii)

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.