zoukankan      html  css  js  c++  java
  • 10.21

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
    tools:context=".MainActivity">
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用户名:"
        android:textSize="20dp"
        android:layout_marginTop="50dp"
        />
    <EditText
        android:id="@+id/et1"
        android:layout_width="500dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv1"
        android:layout_marginTop="40dp"
        android:textSize="20dp"
        />
    
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密码:"
        android:textSize="20dp"
        android:layout_marginTop="40dp"
        android:layout_below="@+id/tv1"
        />
    <EditText
        android:id="@+id/et2"
        android:layout_width="500dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2"
        android:layout_marginTop="20dp"
        android:textSize="30dp"
        android:layout_below="@+id/et1"
    
        />
    
    
        <Button
            android:layout_marginTop="80dp"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="注册"
            android:textSize="40dp"
            android:layout_below="@+id/et2"
            android:layout_centerHorizontal="true"
            android:onClick="click"
            />
    </RelativeLayout>
    package com.example.myapplication;
     
    import android.content.ContentValues;
    import android.os.Bundle;
    import android.app.Activity;
    import android.database.sqlite.SQLiteDatabase;
    import android.view.Menu;
    import android.view.View;
    import android.widget.EditText;
     
    public class MainActivity extends Activity {
     
        private String username;
        private String password;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
     
             
             
        }
     
        public void click(View view){
            username =((EditText) findViewById(R.id.et1)).getText().toString();
            password =((EditText) findViewById(R.id.et2)).getText().toString();
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db =helper.getReadableDatabase();
            ContentValues cv = new ContentValues();
            cv.put("username",username);
            cv.put("password",password);
            db.insert("stu",null,cv);
            db.close();
        }
    }
    package com.example.myapplication;
     
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteDatabase.CursorFactory;
    import android.database.sqlite.SQLiteOpenHelper;
     
    public class StuOpenHelper extends SQLiteOpenHelper{
     
        public StuOpenHelper(Context context) {
            super(context, "stu.db", null, 5);
            // TODO Auto-generated constructor stub
        }
     
        @Override
        public void onCreate(SQLiteDatabase db) {
            System.out.println("第一次创建");
            String sql = "CREATE TABLE stu (_id integer PRIMARY KEY AUTOINCREMENT,USERNAME VARCHAR(20),PASSWORD  VARCHAR(20))";
            db.execSQL(sql);
             
        }
     
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
                System.out.println("更新"+oldVersion+"  "+newVersion);
                if(oldVersion==5 && newVersion==6) {
                    String sql = "CREATE TABLE bj (_id integer PRIMARY KEY AUTOINCREMENT,CLASSNAME VARCHAR(20))";
                    db.execSQL(sql);
                }
     
        }
    }
  • 相关阅读:
    mySql基础
    ECSHOP模糊分词搜索和商品列表关键字飘红功能
    smarty在循环的时候计数来显示这是第几次循环的功能
    PHP Warning: 的解决方法
    ECSHOP生成缩略图模糊
    ECSHOP商品描述和文章里不加水印,只在商品图片和商品相册加水印
    ECSHOP_百度收录网址后面有?from=rss
    在ecshop中添加页面,并且实现后台管理
    windows 2003子目录权限丢失及子目录权限无法继承更改的解决方法
    Newtonsoft.Json初探
  • 原文地址:https://www.cnblogs.com/Inati/p/14000521.html
Copyright © 2011-2022 走看看