Android 仿iphone提醒事項(三)

前面已經把主界面做出來了,程序還有很重要的一部分就是數據庫的搭建了

其中數據庫表信息,包括表名,時間,地點,消息,是否重複鬧鐘,是否開啓這些信息,其中一張表對應一個數據庫表

db.execSQL("CREATE TABLE table_one(_id INTEGER PRIMARY KEY AUTOINCREMENT, title text, time text , location text , note text ,repeat int ,is_check int)");

數據庫相關使用方法SQLHelper.java

package com.iphone.reminder.sqlite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.iphone.reminder.util.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SQLHelper {

	private static String SQL_NAME = "reminder_db_test2";
	private static String TABLE_NAME_ONE = "table_one";
	private static String TABLE_NAME_TWO = "table_two";
    private static String TABLE_NAME_THREE = "table_three";
    private static String TABLE_NAME_FOUR = "table_four";
    private static String TABLE_NAME = TABLE_NAME_ONE;

    /**
     * 創建數據庫
     */
    public static void createSql(Context context) {
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        @SuppressWarnings("unused")
        SQLiteDatabase db = dbHelper.getReadableDatabase();
    }

	// 插入數據
    public static void insertSqlite(Context context, String title, String time,
                                    String location, String note, int tableCount, int repeatNum, int isCheck) {
        ContentValues values = new ContentValues();
        values.put("title", title);
        values.put("time", time);
        values.put("location", location);
        values.put("note", note);
        values.put("repeat", repeatNum);
        values.put("is_check", isCheck);
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.insert(getTableName(tableCount), null, values);
        db.close();
	}

	// 插入單項數據
	public static void insertNumber(Context context, String title,int tableCount ) {
		ContentValues values = new ContentValues();
		values.put("title", title);
		DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
		SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.insert(getTableName(tableCount), null, values);
		db.close();
	}

    // 修改是否選中
    public static void updateIsCheckDetail(Context context, String id,int tableCount, int isCheck) {
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("is_check", isCheck);
        db.update(getTableName(tableCount), values, "_id=?", new String[]{id});
        db.close();
    }

    // 修改
    public static void updateNewDetail(Context context, String id, String newTitle, String newTime, String newLocation, String newNote, int tableCount, int newRepeatNum, int isCheck) {
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("title", newTitle);
        values.put("time", newTime);
        values.put("location", newLocation);
        values.put("note", newNote);
        values.put("repeat", newRepeatNum);
        values.put("is_check", isCheck);
        db.update(getTableName(tableCount), values, "_id=?", new String[]{id});
        db.close();
    }

	  /**  
     * 查,查詢表中所有的數據  
     */  
    public static List<Map<String, String>> queryAllMessage(Context context,int tableCount) {  
    	
    	List<Map<String, String>> tempList = new ArrayList<Map<String, String>>();
    	DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.query(getTableName(tableCount), null, null, null, null, null, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                String _id = cursor.getString(cursor.getColumnIndex("_id"));
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String time = cursor.getString(cursor.getColumnIndex("time"));
                String location = cursor.getString(cursor.getColumnIndex("location"));
                String note = cursor.getString(cursor.getColumnIndex("note"));
                String repeat = cursor.getString(cursor.getColumnIndex("repeat"));
                String isCheck = cursor.getString(cursor.getColumnIndex("is_check"));
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID", _id);
                map.put("TITLE", title);
                map.put("TIME", time);
                map.put("LOCATION", location);
                map.put("NOTE", note);
                map.put("REPEAT", repeat);
                map.put("ISCHECK", isCheck);
                tempList.add(map);
                
            }  
            db.close();
        }  
        return tempList;
    }  
    
    /**
     * 在數據庫中搜索關鍵字
     */
    public static List<Map<String, String>> queryAllTitle(Context context,
                                                          String keywords) {
        List<Map<String, String>> tempList = new ArrayList<Map<String, String>>();
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursorOne = db.query(TABLE_NAME_ONE, null, null, null, null,
                null, null);
        Cursor cursorTwo = db.query(TABLE_NAME_TWO, null, null, null, null,
                null, null);

        Cursor cursorThree = db.query(TABLE_NAME_THREE, null, null, null, null,
                null, null);

        Cursor cursorFour = db.query(TABLE_NAME_FOUR, null, null, null, null,
                null, null);
        while (cursorOne.moveToNext()) {// 表一
            String _id = cursorOne.getString(cursorOne.getColumnIndex("_id"));
            String title = cursorOne.getString(cursorOne.getColumnIndex("title"));
            String time = cursorOne.getString(cursorOne.getColumnIndex("time"));
            String location = cursorOne.getString(cursorOne.getColumnIndex("location"));
            String note = cursorOne.getString(cursorOne.getColumnIndex("note"));
            String repeat = cursorOne.getString(cursorOne.getColumnIndex("repeat"));
            String isCheck = cursorOne.getString(cursorOne.getColumnIndex("is_check"));
            if (Utils.iskeywordsSearched(title, keywords)) {// 判斷是否符合搜索
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID", _id);
                map.put("TITLE", title);
                map.put("TIME", time);
                map.put("LOCATION", location);
                map.put("NOTE", note);
                map.put("REPEAT", repeat);
                map.put("ISCHECK", isCheck);
                tempList.add(map);
            } else {

            }
        }

        while (cursorTwo.moveToNext()) {// 表二
            String _id = cursorTwo.getString(cursorTwo.getColumnIndex("_id"));
            String title = cursorTwo.getString(cursorTwo
                    .getColumnIndex("title"));
            String time = cursorTwo.getString(cursorTwo.getColumnIndex("time"));
            String location = cursorTwo.getString(cursorTwo
                    .getColumnIndex("location"));
            String note = cursorTwo.getString(cursorTwo.getColumnIndex("note"));
            String repeat = cursorTwo.getString(cursorTwo.getColumnIndex("repeat"));
            String isCheck = cursorTwo.getString(cursorTwo.getColumnIndex("is_check"));
            if (Utils.iskeywordsSearched(title, keywords)) {// 判斷是否符合搜索
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID", _id);
                map.put("TITLE", title);
                map.put("TIME", time);
                map.put("LOCATION", location);
                map.put("NOTE", note);
                map.put("REPEAT", repeat);
                map.put("ISCHECK", isCheck);
                tempList.add(map);
            } else {

            }
        }

        while (cursorThree.moveToNext()) {// 表三
            String _id = cursorThree.getString(cursorThree.getColumnIndex("_id"));
            String title = cursorThree.getString(cursorThree
                    .getColumnIndex("title"));
            String time = cursorThree.getString(cursorThree.getColumnIndex("time"));
            String location = cursorThree.getString(cursorThree
                    .getColumnIndex("location"));
            String note = cursorThree.getString(cursorThree.getColumnIndex("note"));
            String repeat = cursorThree.getString(cursorThree.getColumnIndex("repeat"));
            String isCheck = cursorThree.getString(cursorThree.getColumnIndex("is_check"));
            if (Utils.iskeywordsSearched(title, keywords)) {// 判斷是否符合搜索
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID", _id);
                map.put("TITLE", title);
                map.put("TIME", time);
                map.put("LOCATION", location);
                map.put("NOTE", note);
                map.put("REPEAT", repeat);
                map.put("ISCHECK", isCheck);
                tempList.add(map);
            } else {

            }
        }


        while (cursorFour.moveToNext()) {// 表四
            String _id = cursorFour.getString(cursorFour.getColumnIndex("_id"));
            String title = cursorFour.getString(cursorFour
                    .getColumnIndex("title"));
            String time = cursorFour.getString(cursorFour.getColumnIndex("time"));
            String location = cursorFour.getString(cursorFour
                    .getColumnIndex("location"));
            String note = cursorFour.getString(cursorFour.getColumnIndex("note"));
            String repeat = cursorFour.getString(cursorFour.getColumnIndex("repeat"));
            String isCheck = cursorFour.getString(cursorFour.getColumnIndex("is_check"));
            if (Utils.iskeywordsSearched(title, keywords)) {// 判斷是否符合搜索
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("ID", _id);
                map.put("TITLE", title);
                map.put("TIME", time);
                map.put("LOCATION", location);
                map.put("NOTE", note);
                map.put("REPEAT", repeat);
                map.put("ISCHECK", isCheck);
                tempList.add(map);
            } else {

            }
        }

        db.close();
        return tempList;
    }


    /**
     * 全部4張表數據
     */
    public static List<Map<String, String>> queryAllData(Context context) {
        List<Map<String, String>> tempList = new ArrayList<Map<String, String>>();
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursorOne = db.query(TABLE_NAME_ONE, null, null, null, null,
                null, null);
        Cursor cursorTwo = db.query(TABLE_NAME_TWO, null, null, null, null,
                null, null);

        Cursor cursorThree = db.query(TABLE_NAME_THREE, null, null, null, null,
                null, null);

        Cursor cursorFour = db.query(TABLE_NAME_FOUR, null, null, null, null,
                null, null);

        while (cursorTwo.moveToNext()) {// 表二
            String _id = cursorTwo.getString(cursorTwo.getColumnIndex("_id"));
            String title = cursorTwo.getString(cursorTwo
                    .getColumnIndex("title"));
            String time = cursorTwo.getString(cursorTwo.getColumnIndex("time"));
            String location = cursorTwo.getString(cursorTwo
                    .getColumnIndex("location"));
            String note = cursorTwo.getString(cursorTwo.getColumnIndex("note"));
            String repeat = cursorTwo.getString(cursorTwo.getColumnIndex("repeat"));
            String isCheck = cursorTwo.getString(cursorTwo.getColumnIndex("is_check"));
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("ID", _id);
            map.put("TITLE", title);
            map.put("TIME", time);
            map.put("LOCATION", location);
            map.put("NOTE", note);
            map.put("REPEAT", repeat);
            map.put("ISCHECK", isCheck);

            tempList.add(map);
        }

        while (cursorThree.moveToNext()) {// 表三
            String _id = cursorThree.getString(cursorThree.getColumnIndex("_id"));
            String title = cursorThree.getString(cursorThree
                    .getColumnIndex("title"));
            String time = cursorThree.getString(cursorThree.getColumnIndex("time"));
            String location = cursorThree.getString(cursorThree
                    .getColumnIndex("location"));
            String note = cursorThree.getString(cursorThree.getColumnIndex("note"));
            String repeat = cursorThree.getString(cursorThree.getColumnIndex("repeat"));
            String isCheck = cursorThree.getString(cursorThree.getColumnIndex("is_check"));

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("ID", _id);
            map.put("TITLE", title);
            map.put("TIME", time);
            map.put("LOCATION", location);
            map.put("NOTE", note);
            map.put("REPEAT", repeat);
            map.put("ISCHECK", isCheck);

            tempList.add(map);

        }


        while (cursorFour.moveToNext()) {// 表四
            String _id = cursorFour.getString(cursorFour.getColumnIndex("_id"));
            String title = cursorFour.getString(cursorFour
                    .getColumnIndex("title"));
            String time = cursorFour.getString(cursorFour.getColumnIndex("time"));
            String location = cursorFour.getString(cursorFour
                    .getColumnIndex("location"));
            String note = cursorFour.getString(cursorFour.getColumnIndex("note"));
            String repeat = cursorFour.getString(cursorFour.getColumnIndex("repeat"));
            String isCheck = cursorFour.getString(cursorFour.getColumnIndex("is_check"));

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("ID", _id);
            map.put("TITLE", title);
            map.put("TIME", time);
            map.put("LOCATION", location);
            map.put("NOTE", note);
            map.put("REPEAT", repeat);
            map.put("ISCHECK", isCheck);

            tempList.add(map);
        }

        while (cursorOne.moveToNext()) {// 表一放最後保證總表添加數據在最後
            String _id = cursorOne.getString(cursorOne.getColumnIndex("_id"));
            String title = cursorOne.getString(cursorOne.getColumnIndex("title"));
            String time = cursorOne.getString(cursorOne.getColumnIndex("time"));
            String location = cursorOne.getString(cursorOne.getColumnIndex("location"));
            String note = cursorOne.getString(cursorOne.getColumnIndex("note"));
            String repeat = cursorOne.getString(cursorOne.getColumnIndex("repeat"));
            String isCheck = cursorOne.getString(cursorOne.getColumnIndex("is_check"));

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("ID", _id);
            map.put("TITLE", title);
            map.put("TIME", time);
            map.put("LOCATION", location);
            map.put("NOTE", note);
            map.put("REPEAT", repeat);
            map.put("ISCHECK", isCheck);

            tempList.add(map);
        }

        db.close();
        return tempList;
    }

    // 刪除某條消息
    public static void deleteDetailDate(Context context, String id, int tableCount) {
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.delete(getTableName(tableCount), "_id=?", new String[]{id});
        db.close();
    }

    public static void deleteAll(Context context, int tableCount) {
        DatabaseHelper dbHelper = new DatabaseHelper(context, SQL_NAME);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.delete(getTableName(tableCount), null, null);
        db.close();
    }

    public static String getTableName(int tableCount) {
        switch (tableCount) {
            case 1:
                TABLE_NAME = TABLE_NAME_ONE;
                break;
            case 2:
                TABLE_NAME = TABLE_NAME_TWO;
                break;
            case 3:
                TABLE_NAME = TABLE_NAME_THREE;
                break;
            case 4:
                TABLE_NAME = TABLE_NAME_FOUR;
                break;
        }
        return TABLE_NAME;
    }
}

這裏還沒有對數據進行動態表處理,列了小於等於4張表的情況,以後在做補充

這裏有一個注意點就是數據庫數據是可以刪除的,所以數據庫數據和adapter結合的時候需要注意刪除數據的情況

工具類:封裝了一些要使用到的方法和上面提到的數據庫和adapter使用的數據轉換

package com.iphone.reminder.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.iphone.reminder.activity.TestActivity;
import com.iphone.reminder.broadcast.ReminderBroadcast;
import com.iphone.reminder.data.MessageBean;
import com.iphone.reminder.sqlite.SQLHelper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class Utils {
    public static final int TO_Y_VALUE = 1050;
    public static final int MARGIN_GAP = 150;
    public static final int BOTTOM_GAP=5;
    public static final int SEY_Y = TO_Y_VALUE + MARGIN_GAP;
    public static boolean isShow = false;
    public static final int TABLE_COUNT_ONE = 1;
    public static final int TABLE_COUNT_TWO = 2;
    public static final int TABLE_COUNT_THREE = 3;
    public static final int TABLE_COUNT_FOUR = 4;

    public static final String TABLE_COUNT = "table_count";
    public static final String TABLE_COUNT_KEY = "table_count_key";
    public static final String TABLE_TITLE = "title";
    public static final String TABLE_COLOR = "colors";

    public static final String TABLE_TITLE_KEY = "TITLE";
    public static final String TABLE_COLOR_KEY = "CURRENT_TABLE";
    /**
     * 判斷軟鍵盤是否彈出
     */
    public static boolean isSoftShowing(Activity mActivity) {
        // 獲取當前屏幕內容的高度
        int screenHeight = mActivity.getWindow().getDecorView().getHeight();
        // 獲取View可見區域的bottom
        Rect rect = new Rect();
        mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        return screenHeight - rect.bottom != 0;
    }

    /**
     * 把數據庫數據轉到可以讓adapter使用的ArrayList數據
     */
    public static ArrayList<MessageBean> addTableOneDetailsDate(Context mContext) {
        SQLHelper.createSql(mContext);

        List<Map<String, String>> listTemp = SQLHelper.queryAllData(
                mContext);// 調用數據庫數據
        ArrayList<MessageBean> mMessageList = new ArrayList<MessageBean>();
        if (listTemp.size() > 0) {
            for (int i = 0; i < listTemp.size(); i++) {
                MessageBean item = new MessageBean();
                item.title = listTemp.get(i).get("TITLE");
                item.time = listTemp.get(i).get("TIME");
                item.location = listTemp.get(i).get("LOCATION");
                item.note = listTemp.get(i).get("NOTE");
                item.repeat = Integer.valueOf(listTemp.get(i).get("REPEAT"));
                item.isCheck = listTemp.get(i).get("ISCHECK").equals("0")?false:true;
                mMessageList.add(item);
            }
        }

        return mMessageList;
    }

    /**
     * 把數據庫數據轉到可以讓adapter使用的ArrayList數據
     */
    public static ArrayList<MessageBean> addDetailsDate(Context mContext,
                                                        int tabelCount) {
        SQLHelper.createSql(mContext);

        List<Map<String, String>> listTemp = SQLHelper.queryAllMessage(
                mContext, tabelCount);// 調用數據庫數據
        ArrayList<MessageBean> mMessageList = new ArrayList<MessageBean>();
        if (listTemp.size() > 0) {
            for (int i = 0; i < listTemp.size(); i++) {
                MessageBean item = new MessageBean();
                item.title = listTemp.get(i).get("TITLE");
                item.time = listTemp.get(i).get("TIME");
                item.location = listTemp.get(i).get("LOCATION");
                item.note = listTemp.get(i).get("NOTE");
                item.repeat = Integer.valueOf(listTemp.get(i).get("REPEAT"));
                item.isCheck = listTemp.get(i).get("ISCHECK").equals("0")?false:true;
                if(!Utils.isShow&&item.isCheck) {
                }else{
                    mMessageList.add(item);
                }
            }
        }

        return mMessageList;
    }


    /**
     * 把數據庫數據轉到可以讓adapter使用的ArrayList數據
     */
    public static ArrayList<MessageBean> addSearchData(Context mContext, String keywords) {
        SQLHelper.createSql(mContext);

        List<Map<String, String>> listTemp = SQLHelper.queryAllTitle(
                mContext, keywords);// 調用數據庫數據
        ArrayList<MessageBean> mMessageList = new ArrayList<MessageBean>();
        if (listTemp.size() > 0) {
            for (int i = 0; i < listTemp.size(); i++) {
                MessageBean item = new MessageBean();
                item.title = listTemp.get(i).get("TITLE");
                item.time = listTemp.get(i).get("TIME");
                item.location = listTemp.get(i).get("LOCATION");
                item.note = listTemp.get(i).get("NOTE");
                item.repeat = Integer.valueOf(listTemp.get(i).get("REPEAT"));
                item.isCheck = listTemp.get(i).get("ISCHECK").equals("0")?false:true;
                mMessageList.add(item);
            }
        }

        return mMessageList;
    }


    /**
     * 一次性鬧鐘
     */
    public static void singleReminder(Activity activity, Context context,
                                      String title, String note, long timeStamp, String currentTime) {
        Intent intent = new Intent(activity, ReminderBroadcast.class);
        intent.setAction("VIDEO_TIMER");
        intent.putExtra("TITLE", title);
        intent.putExtra("NOTE", note);
        intent.putExtra("CTIME", currentTime);
        PendingIntent sender = PendingIntent.getBroadcast(activity, 0, intent,
                0);

        AlarmManager am = (AlarmManager) context
                .getSystemService(context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, timeStamp,
                sender);
    }

    /**
     * 重複鬧鐘
     */
    public static void alarmRepeatReminder(Activity activity, Context context,
                                           String title, String note, long timeStamp, long intervalMillis, String currentTime) {
        Intent intent = new Intent(activity, ReminderBroadcast.class);
        intent.setAction("VIDEO_TIMER");
        intent.putExtra("TITLE", title);
        intent.putExtra("NOTE", note);
        intent.putExtra("CTIME", currentTime);
        Log.d("cfb","utils===="+title+"---note=="+note+"````currentTime---"+currentTime);
        // PendingIntent這個類用於處理即將發生的事情
        PendingIntent sender = PendingIntent.getBroadcast(activity, 0, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        @SuppressWarnings("static-access")
        AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
        am.setRepeating(AlarmManager.RTC_WAKEUP,
                timeStamp, intervalMillis, sender);
    }

    /**
     * 將字符串轉爲時間戳
     */
    @SuppressLint("SimpleDateFormat")
    public static String getTime(String user_time) {
        String re_time = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = null;
        try {
            d = sdf.parse(user_time);
        } catch (java.text.ParseException e) {
            e.printStackTrace();
        }
        long l = d.getTime();
        String str = String.valueOf(l);
        re_time = str.substring(0, 10);

        return re_time;
    }

    /**
     * 判斷搜索條件
     */
    public static boolean iskeywordsSearched(String titleStr, String keywords) {
        if (titleStr.indexOf(keywords) != -1) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isValidTime(long date1, long date2) {
        //SimpleDateFormat currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        boolean isValidTime = false;
        //try {

            //double beginTime = currentTime.parse(date1);
            //double endTime = currentTime.parse(date2);

            if(date2-date1>0){
                isValidTime =  true;
            }else{
                isValidTime =  false;
            }
           Log.d("cfb","isValidTime==="+isValidTime);
        /*} catch (java.text.ParseException e) {
            e.printStackTrace();
        }*/
        return  isValidTime;
    }

    //判斷當前軟鍵盤狀態
    public static boolean isHideOrShowImm(View v){
        InputMethodManager imm = (InputMethodManager) TestActivity.mTestActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if(imm.hideSoftInputFromWindow(v.getWindowToken(), 0))
        {
            //軟鍵盤已彈出
            return true;
        }
        else
        {
            //軟鍵盤未彈出
            return false;
        }

    }

    // 隱藏輸入法
    public static void hideImm(){

            InputMethodManager imm = (InputMethodManager) TestActivity.mTestActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

所以有在建表的時候加入數據

ListStyleView mListStyleView = new ListStyleView(getApplicationContext(), Utils.addDetailsDate(getApplicationContext(), mListStyleViewList.size() + 1), mListStyleViewList.size() + 1);

直接將數據傳入ListStyleView 表中,再將該數據放入adapter中:

mYAdpter.setmMessageItems(mMessageList);


在adapter就可以輕鬆的通過getview遍歷取出數據使用

MessageBean item = mMessageItems.get(position);
MessageBen 中就是get/set數據庫中的信息

package com.iphone.reminder.data;

import com.iphone.reminder.listview.SlideView;

public class MessageBean {
	
	private int id;
	public String title;
	public String time;
	public String location;
	public String note;
    public int repeat;
    public boolean isCheck;

	public SlideView slideView;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getLocation() {
		return location;
	}

    public int getRepeat(int repeat){
        return repeat;
    }

	public void setLocation(String location) {
		this.location = location;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public SlideView getSlideView() {
		return slideView;
	}

	public void setSlideView(SlideView slideView) {
		this.slideView = slideView;
	}
}

到這裏我們就可以看到主界面的數據了。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章