Android Project-use SQLite database to develop news release system

Source: Internet
Author: User
Tags sqlite database

This tutorial is dedicated to programmers who can quickly learn Android mobile phone development.

Suitable for colleagues who have acquired a programming language.

More like-minded, want to learn more programming technology of the Great Gods.

My little brother, please pay attention to my today headline-Do the full stack siege lion.

This article is based on the previous article on the basis of deep learning. Programmers take you on the creation and parsing of-xml documents for Android development

SQLite database:

SQLite database is a widely used database in Android. It is a simple, lightweight SQL-class file-type database. Security is not very high because it is saved in a simple text format. You can get the data as long as you get the SQLite database file. Therefore, it is decided that SQLite database is not suitable for preserving more privacy important data.

For easy editing of the SQLite database, we use a SQLite database visualizer on this side. Navicat Premium.

I have found a relatively good version here. Share to you. : https://yunpan.cn/cM9wzNM4KefD8 access password 6A40 Software installation is simple. Step by step the installation is successful. Installation opened successfully

Naviate: You can link to most of the database engine, and simple operation, support powerful code intelligence hints and so on. Recommended for everyone to use.

First, naviate software use

1. Create a SQLite database:

Configure database-related data

The link name is the name of the item displayed on the left and can be customized. At this point we found that a first.db file was generated on the desktop.

That's right, this is SQLite's database file. All the data is stored in this file.

2. Open the existing database file:

Open the link to open the success.

3. We can initialize the database structure and data, for example:

3.1 Adding the News table

CREATE TABLE "News" (

"Id" INTEGER not NULL,

"Title" TEXT,

"Content" TEXT,

PRIMARY KEY ("Id")

);

3.2 Initializing data:

Add only two rows of data to join here: News:

INSERT into "News" VALUES (' 1 ', ' English class four high-frequency vocabulary, pure dry Goods, collection ', ' 1.alter [') '?: Lt?] v. Change, modify, change 2.burst [' b?:ð?n] vi.,n. Suddenly, burst 3.dispos e [dis ' p?uz] vi. to dispose of; handle (of) 4.blast [Blɑ:st] n. explosion; air Flow VI. Blow up, blow up 5.consume [k?n ' sju:m] v. Consume, drain the headline number/Do the full stack siege lion ');

INSERT into "News" VALUES (' 2 ', ' recommend a few more useful tools for ASP. 2 ', ' recommended a few useful tools for ASP. We have the relevant tools can also be in the comment area message, work together to study.

As a programmer to be challenging, you can try these tools. ‘);

It's pretty much the same as the native SQL syntax. If you look at it, it shouldn't be a big problem for you.

Second, use the Android code to manipulate the database:

1. We continue to do a press release management system:

The foreground interface effect, very simple layout operation. Here I put my layout, for reference.

2.Sqlite Database operations:

2.1 Initialize the control in the OnCreate method:

Private EditText Edittitle;

Private EditText editcontent;

@Override

protected void OnCreate (Bundle savedinstancestate)

{

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.activity_main);

Edittitle = (EditText) Findviewbyid (r.id.edittitle);

Editcontent = (EditText) Findviewbyid (r.id.editcontent);

}

2.2 The Save button binds the background save method to get the news information entered by the User:

2.2.1 User input information preprocessing:

public void Save (View v)

{

String title = Edittitle.gettext (). toString (). Trim ();

String content = Editcontent.gettext (). toString (). Trim ();

if (Textutils.isempty (title) | | Textutils.isempty (content))

{

Toast.maketext (Mainactivity.this, "incomplete information completed", Toast.length_short). Show ();

Return

}

}

3. Save the user-entered news information to the database:

3.1 New newssqlitehelper inherit from Sqliteopenhelper. Used to maintain and create databases.

3.2 Create a News object that corresponds to the news table:

3.3 DAO action class for new Action News table:

Because of the news release system, only to increase the news, temporarily create a method to add data. The following article explains: News list display feature.

3.4 Saving data to the database:

News news = new News ();

News.settitle (title);

News.setcontent (content);

Newsdao dao = new Newsdao (mainactivity.this);

Dao.add (news);

Toast.maketext (Mainactivity.this, "add Success", Toast.length_short). Show ();

4. Final effect

We use Android Device Monitor. Export the resulting database file.

Open Android Device Monitor:

Locate the database file export:

Use Naviate to view the database data.

At this point a simple press release system is completed. The following section explains the use of SQLite for "News display System"

Please click here for the latest tutorials

Today's headline-Do the full stack siege lion.

QQ Technology Group number: 538742639

Android Project-use SQLite database to develop news release system

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.