2015 Android Case tour case eight: Registration calendar knowledge Points:
- Use of the GridView
- Use of SQLite
Documents involved:
- Res->layout->activity_main.xml Main layout file
- Res->layout->date.xml Layout file
- Src->db->dbhelper.javajava file
- Src->db->signdao.javajava file
- Src->activity->mainactivity.javajava file
Activity_main.xml
<!--linear layout--><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" android:layout _height= "Match_parent" android:layout_width= "match_parent" android:orientation= "vertical" > < !--Text Control Displays the current month-- <textview android:id= "@+id/show" android:gravity= "center" android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:text= "month"/> <!-- Grid View- <gridview android:id= "@+id/mydate" android:layout_width= "Match_parent" android:layout_height= "355DP" android:numcolumns= "7" ></GridView> <button Android:id= "@+id/sign" android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:text= "Sign in"/></linearlayout>
Date.xml
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:orientation=" vertical "> <textview Android:id= "@+id/txtweekdatemb" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content " android:layout_marginleft=" 10DP " android:layout_margintop=" 10DP " android:visibility=" gone "/> <textview android:id=" @+id/txtdaydatemb " android:layout_width= " Wrap_content " android:layout_height= "Wrap_content" android:layout_marginleft= "10DP" android:layout_margintop= "10DP "/></linearlayout>
Mainactivity.java
public class Mainactivity extends Activity {//log label private static final String tag = "sign";//Declare Object private Button Sign;priv Ate TextView show;private GridView mydate;//get local time-nowtime = new Times ();//days in one months private int daymaxnum;private int yea R,month,day,ym;private Signdao sdao;//Query result private list<string> List = new arraylist<string> ();p rivate ArraylistDbhelper.java
public class DBHelper extends Sqliteopenhelper {public DBHelper (context context) {Super (context, "sign.db", NULL, 1);} /** * @param CREATE TABLE */@Overridepublic void OnCreate (Sqlitedatabase db) {String sql= "CREATE TABLE Sintb (" + "sin_id integer prim ary key AutoIncrement, "+" userid varchar (a), "+" usernmae varchar (+), "+" sindate varchar (20), "+" yearmonth varchar, "+" Nowdate integer "+") ";d b.execsql (SQL);} /** * This method is called when @param database version is updated */@Overridepublic void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {}}
Signdao.java
public class Signdao {//Declare object context context; Sqlitedatabase db;dbhelper dbhelper;public Signdao (context context) {This.context = context;} /** * @param Open database Connection */public Boolean open () {dbhelper = new DBHelper (context);d B = dbhelper.getwritabledatabase (); if (db = = NULL) {return false;} return true;} /** * @param close connection */public void Close () {dbhelper.close ();} /** * @param Insert information * @param UID * @param name * @param date * @param ym */public void Insertsininfo (String uid,string name,s Tring date,string month) {String sql= "insert into SINTB (userid,usernmae,sindate,yearmonth,nowdate) VALUES (?,?,?,?,?)"; Db.execsql (Sql,new Object[]{uid,name,date,month,system.currenttimemillis ()}); /** * @param query information * @param UID * @param date * @param ym * @return */public arraylist
My Android Case-sign-in Calendar