zoukankan      html  css  js  c++  java
  • 安卓

    package com.example.bbb;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.ContentValues;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.view.Menu;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    public class MainActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
        public void add(View v) {
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db = helper.getWritableDatabase();
            String name = ((EditText) findViewById(R.id.et_name)).getText()
                    .toString();
            int age = Integer.parseInt(((EditText) findViewById(R.id.et_age))
                    .getText().toString());
            db.execSQL("insert into stuinfo (name,age) values(?,?)", new Object[] {
                    name, age });
            Toast.makeText(this, "ok", 0).show();
        }
        public void delete(View view) {
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db = helper.getWritableDatabase();
            db.execSQL("delete from stuinfo where _id=?", new Object[] { 2 });
            Toast.makeText(this, "删除成功", 0).show();
        }
        public void update(View view) {
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db = helper.getWritableDatabase();
            db.execSQL("update stuinfo set name=? where _id=?", new Object[] {
                    "micky", 3 });
            Toast.makeText(this, "修改成功", 0).show();
        }
    
        public void search(View view) {
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db = helper.getWritableDatabase();
            String s = "";
            Cursor cursor = db.rawQuery("select * from stuinfo", null);
            if (cursor.getCount() != 0) {
    
                while (cursor.moveToNext()) {
                    s += cursor.getInt(0) + "   " + cursor.getString(1) + "   "
                            + cursor.getInt(2) + "
    ";
                }
            }
            ((TextView) (findViewById(R.id.tv_show))).setText(s);
        }
    }
    

      

    package com.example.bbb;
    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, 1);
        }
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table stuinfo(_id integer primary key autoincrement,name varchar(20),age integer)");
        }
        @Override
        public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
        }
    }
    

      

    <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout android:padding="16dp" android:orientation="vertical" android:background="@drawable/bg" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
        <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="130dp">
            <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="18sp" android:text="姓 名 :"/>
            <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:textSize="16sp" android:hint="请输入姓名" android:id="@+id/et_name"/>
        </LinearLayout>
        -<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginBottom="10dp">
        <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="18sp" android:text="年 龄:"/>
        <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:textSize="16sp" android:hint="输入年龄" android:id="@+id/et_age"/>
    </LinearLayout>
        -<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:background="#B9B9FF" android:layout_height="wrap_content" android:layout_width="0dp" android:textSize="18sp" android:text="添加" android:id="@+id/btn_add" android:onClick="add" android:layout_weight="1" android:layout_marginRight="2dp"/>
        <Button android:background="#DCB5FF" android:layout_height="wrap_content" android:layout_width="0dp" android:textSize="18sp" android:text="查询" android:id="@+id/btn_query" android:onClick="search" android:layout_weight="1" android:layout_marginRight="2dp"/>
        <Button android:background="#E6CAFF" android:layout_height="wrap_content" android:layout_width="0dp" android:textSize="18sp" android:text="修改" android:id="@+id/btn_update" android:onClick="update" android:layout_weight="1" android:layout_marginRight="2dp"/>
        <Button android:background="#ACD6FF" android:layout_height="wrap_content" android:layout_width="0dp" android:textSize="18sp" android:text="删除" android:id="@+id/btn_delete" android:onClick="delete" android:layout_weight="1"/>
    </LinearLayout>
        -<ScrollView android:layout_height="wrap_content" android:layout_width="match_parent">
        <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="25dp" android:textSize="20sp" android:id="@+id/tv_show"/>
    </ScrollView>
    </LinearLayout>
    

      

  • 相关阅读:
    读胶料温度代码
    干掉win10自带的不给力的应用(转自https://jingyan.baidu.com/article/08b6a591b7398514a8092238.html)
    安装SQL提示重启电脑失败,解决办法
    几种加解密方法:AES、DES、SHA数据加密
    SQL数据库添加新账号,只操作指定数据库
    jQuery中attr()、prop()、data()用法及区别
    jquery.cookie() 的使用(原)
    功能强大的web打印控件lodop的使用
    Win+R命令大全
    Vue
  • 原文地址:https://www.cnblogs.com/wu-di-821-821/p/14134553.html
Copyright © 2011-2022 走看看