<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" tools:context=".MainActivity" > <TextVIEw androID:ID="@+ID/textVIEw" androID:layout_wIDth="match_parent" androID:layout_height="40dp" androID:background="#00BCD4" androID:gravity="center" androID:text="学生注册页面" androID:textSize="30sp" androID:textStyle="bold" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <tableLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="50dp"> <tableRow androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:gravity="center"> <TextVIEw androID:ID="@+ID/textVIEw3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="姓名:" /> <EditText androID:ID="@+ID/e_name" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ems="10" androID:inputType="textPersonname" /> </tableRow> <tableRow androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:gravity="center"> <TextVIEw androID:ID="@+ID/textVIEw4" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="年龄:" /> <EditText androID:ID="@+ID/e_age" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ems="10" androID:inputType="textPersonname" /> </tableRow> </tableLayout> <button androID:ID="@+ID/button" androID:layout_wIDth="150dp" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:layout_margin="100dp" androID:gravity="center" androID:text="注册" androID:textSize="20sp" androID:textStyle="bold" /> </linearLayout></linearLayout>package com.example.blj;import androIDx.appcompat.app.AppCompatActivity;import androID.content.ContentValues;import androID.database.sqlite.sqliteDatabase;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.TextVIEw;public class MainActivity extends AppCompatActivity { private button button; private TextVIEw name; private EditText age; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); button = (button)findVIEwByID(R.ID.button); name = (TextVIEw)findVIEwByID(R.ID.e_name); age = (EditText) findVIEwByID(R.ID.e_age); button.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { insert(name.getText().toString(),age.getText().toString()); } }); } public voID insert(String name,String age){ Student helper = new Student(this); sqliteDatabase db = helper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("name",name); values.put("age",age); long ID = db.insert("stu",null,values); db.close(); }}package com.example.blj;import androID.content.Context;import androID.database.sqlite.sqliteDatabase;import androID.database.sqlite.sqliteOpenHelper;import androIDx.annotation.Nullable;public class Student extends sqliteOpenHelper { public Student(@Nullable Context context) { super(context, "student.db", null, 3); } @OverrIDe public voID onCreate(sqliteDatabase db) { String sql = "CREATE table stu(s_ID INTEGER PRIMARY KEY autoINCREMENT,name VARCHAR(20),age INTEGER)"; db.execsql(sql); } @OverrIDe public voID onUpgrade(sqliteDatabase db, int i, int i1) { String sql = "CREATE table bj(b_ID INTEGER PRIMARY KEY autoINCREMENT,b_name VARCHAR(20))"; db.execsql(sql); }}
总结
以上是内存溢出为你收集整理的10.28全部内容,希望文章能够帮你解决10.28所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)