使用android自带的日历控件怎么标记特定的
1个回答
展开全部
初始情况
点击一个作为标记
再次点击后删除
3.这里还要感谢前辈的代码作为参考,毕竟以前也没有写过关于日历方面的东西,别人确实写得不错,我在原基础上加入了数据库操作等补充,以完成自己实际需求,作为尊重首先给出原作者的连接
就是这里–>Android自定义控件实现可多选课程日历CalendarView
4.然后贴出来关于数据库操作的代码,给大家作为参考
DatabaseHelper .java 这是关于简单数据库操作的部分
package com.xugongming38.editcalendar.utils; import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper; /** * Created by dell on 2017/5/18. */ public class DatabaseHelper extends SQLiteOpenHelper { public static final String CREATE_DIARY = "create table Hair(" + "id integer primary key autoincrement, " + "content text)"; private Context mContext; public DatabaseHelper(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_DIARY); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("drop table if exists Hair"); onCreate(db); }}DataHelper .java 简化数据操作接口,避免直接操作数据库,做了再一层的封装,建议读者也这样做,可以让代码更清晰,更容易复用
package com.xugongming38.editcalendar.utils; import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList;import java.util.List; /** * Created by dell on 2017/5/18. */ public class DataHelper { public static DatabaseHelper mHelper; public static void deleteData2List(String content) { SQLiteDatabase dbDelete = mHelper.getWritableDatabase(); dbDelete.delete("Hair", "content = ?", new String[]{content}); } public static void addData2List(String content) { SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("content", content); db.insert("Hair", null, values); values.clear(); } public static List<String> getDataList(Context context) { if(mHelper==null){ mHelper = new DatabaseHelper(context, "Hair.db", null, 1); } List<String> dataList = new ArrayList<>(); SQLiteDatabase sqLiteDatabase = mHelper.getWritableDatabase(); Cursor cursor = sqLiteDatabase.query("Hair", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { String content = cursor.getString(cursor.getColumnIndex("content")); dataList.add(content); } while (cursor.moveToNext()); } cursor.close(); return dataList; }}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询