【发布时间】:2015-02-18 01:03:38
【问题描述】:
我有一个列表视图,其中包含图中所示的 sqlite 数据库中的一些数据。
我想通过选择具有上述文本视图的两个日期范围来过滤此列表。如何使用这些文本视图过滤显示的列表?请帮忙..
数据库类
public class AndroidSQLiteData extends SQLiteOpenHelper
{
private static final int DATABASE_VERSION = 1;
// Database Name
public static final String DATABASE_NAME = "expensedata";
// Labels table name
public static final String TABLE_NAME = "expense";
// Labels Table Columns names
public static final String KEY_ID = "id";
public static final String KEY_CATEGORY = "category";
public static final String KEY_MONEY="moneytype";
public static final String KEY_DATE="date";
public static final String KEY_AMOUNT="amount";
public static final String KEY_DESCRIPTION="description";
private SQLiteDatabase db=null;
public AndroidSQLiteData(Context context)
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase sdb)
{
String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_CATEGORY + " TEXT,"+KEY_DATE+ " TEXT," +KEY_MONEY+" TEXT," +KEY_AMOUNT+ " TEXT," +KEY_DESCRIPTION+ " TEXT)";
sdb.execSQL(CREATE_CATEGORIES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void insertData(String category, String date, String amount, String moneytype, String description)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CATEGORY, category);
values.put(KEY_DATE, date);
values.put(KEY_MONEY, moneytype);
values.put(KEY_AMOUNT, amount);
values.put(KEY_DESCRIPTION, description);
// Inserting Row
db.insert(TABLE_NAME, null, values);
db.close();
// Closing database connection
}
public List<String> getAllData(){
List<String> data = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst())
{
do
{
data.add(cursor.getString(1));
}
while (cursor.moveToNext());
}
// closing connection
cursor.close();
db.close();
return data;
}
public void open()
{
if(this.db==null)
{
this.db=this.getWritableDatabase();
}
}
}
【问题讨论】:
-
您必须更新适配器中的数据。如果您使用游标适配器,请发送新查询以查找日期范围之间的结果,然后将其分配给适配器
标签: android listview sorting date filter