跳过ListActivity的SQLite数据空值 [英] Skip null values in ListActivity with SQLite data
问题描述
我可以显示在的TextView
的ID,标题和借来的值。我的问题是,我想检查借的价值观,如果他们不是空
,显示一个简单的图像。如果该值为空
,我不想显示任何内容。
可能与一个 ViewBinder
工作,但我不知道如何解决此问题。
私有静态的String [] FROM = {_ID,TITLE,借};
私有静态的String [] TO = {R.id.id,R.id.title,R.id.borrowed};私人光标getMovies(){
SQLiteDatabase分贝= movies.getReadableDatabase();
光标光标= db.query(TABLE_NAME,FROM,NULL,NULL,NULL,NULL,ORDER_BY);
startManagingCursor(光标);
返回游标;
}私人无效showTitles(光标光标){
SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,R.layout.item,光标,FROM,TO);
setListAdapter(适配器);
}
扩展您的SimpleCursorAdapter并为您在您的overrided bindView()方法借用val的空。事情是这样的:
私有类mySimpleCursorAdapter扩展SimpleCursorAdapter { @覆盖
公共无效bindView(查看视图,上下文的背景下,光标光标){
如果(cursor.isNull(cursor.getColumnIndex(借用))){
//处理空的场景
}其他{
//处理不为空的情况
}
}
}
这是不是测试,还有其他code,你需要实现,但是这是这个想法。
I can show the id, title and borrowed values in a TextView
. My problem is that I would like to check the "borrowed" values, and if they are not null
, display a simple image. If the value is null
, I don't want to display anything.
Might work with a ViewBinder
, but I don't know how to solve this.
private static String[] FROM = { _ID, TITLE, BORROWED };
private static String[] TO = { R.id.id, R.id.title, R.id.borrowed };
private Cursor getMovies() {
SQLiteDatabase db = movies.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY);
startManagingCursor(cursor);
return cursor;
}
private void showTitles(Cursor cursor) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO);
setListAdapter(adapter);
}
Extend your SimpleCursorAdapter and check for null of the BORROWED val in your overrided bindView() method. Something like this:
private class mySimpleCursorAdapter extends SimpleCursorAdapter{
@Override
public void bindView(View view, Context context, Cursor cursor) {
if ( cursor.isNull( cursor.getColumnIndex(BORROWED) ) ){
// Handle NULL scenario
} else {
// Handle not NULL scenario
}
}
}
This is not tested and there's other code you'll need to implement, but this is the idea.
这篇关于跳过ListActivity的SQLite数据空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!