編輯:關於Android編程
借助SQLiteOpenHelper幫助類實現對數據庫的創建和升級。
MainActivity.java
package com.example.databasetest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private MyDatabaseHelper dbHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dbHelper = new MyDatabaseHelper(this,"BookStore.db",null,1); Button createDatabase =(Button)findViewById(R.id.create_database); createDatabase.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ dbHelper.getWritableDatabase(); } }); } }
MyDatabaseHelper.java
package com.example.databasetest; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; /** * Created by Codingbo on 2017/1/19. */ public class MyDatabaseHelper extends SQLiteOpenHelper { public static final String CREATE_BOOK = "create table Book( " + "id integer primary key autoincrement," +"author text,"+"preice real,"+"pages integer,"+"name text)"; private Context mContext; public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){ super(context,name,factory,version); mContext=context; } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_BOOK); Toast.makeText(mContext,"Create succeed",Toast.LENGTH_SHORT).show(); } @Override public void onUpgrade(SQLiteDatabase ad, int oldVersion, int newVersion) { } }
activity_main
前面我們介紹了AlertDialog和幾個常用的Dialog,ProgressDialog進度條提示框、DatePickerDialog日期選擇對話框和TimePicke
異步加載之使用多線程初次嘗試異步、異步,其實說白了就是多任務處理,也就是多線程執行,多線程那就會有各種問題,我們一步步來看,首先,我們創建一個class—&m
我們在用手機的時候,如果來了短信,而我們沒有點擊查看的話,是不是在手機的最上邊的狀態欄裡有一個短信的小圖標提示啊?你是不是也想實現這種功能呢?今天的Notificatio
Fragment代表了在Activity中的一種或者一部分行為,你可以在單個的activity中連接多個fragment來構建一個多面板的UI,並且在多個activit