我有一個列表視圖,其中有一些數據來自sqlite數據庫,如圖所示。如何使用給定的日期範圍篩選android listview
我想通過選擇上面的文本視圖中的兩個日期範圍過濾此列表。如何使用這些文本視圖過濾顯示的列表?請幫助..
數據庫類
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();
}
}
}
您必須更新適配器中的數據。如果使用遊標適配器,請發送新的查詢以查找日期範圍內的結果,然後將其分配給適配器 – Panther 2014-12-19 05:31:06