SQLite的查询检索所有的行不为空的android [英] sqlite query to retrieve all rows where not null android

查看:156
本文介绍了SQLite的查询检索所有的行不为空的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我喜欢这里2问题:

Good day, I have like 2 question here:

首先一个背景资料。

从Android文档,查询数据库时,我们必须返回一列名为_id为它与游标适配器工作。现在,在我的实现,可以说我有3列_id,列A,B列。

from the android documentation, when querying a database, we have to return a column with name "_id" for it to work with a cursor adapter. Now in my implementation, lets say i have 3 columns "_id", "column A" "column B".

所以,如果我有我的数据库表,其中在A列的第一个3行填充和B列中的下一个5行充满8条目行。如果我在数据库中查询B列,使用code低于我bindview,光标返回所有这将导致在第3项为空,最后5个项目被显示在我的图片中的GridView行。

so if i have 8 entry rows in my database table, where the 1st 3 rows in column A is filled and the next 5 rows in column B is filled. if i query the database for column B and use the code below in my bindview, the cursor returns all the rows which will result in the first 3 entries being null and the last 5 items being shown in my gridview of images.

这是我的bindView:

here is my bindView:

@Override
public void bindView(View view, Context context, Cursor cursor) {
     ViewHolder holder = (ViewHolder)view.getTag();
 int columnIndex = cursor.getColumnIndexOrThrow(columnName);
 final String name = cursor.getString(columnIndex);
     while(cursor.moveToNext()){

            if(name != null){
             Log.d(TAG, "string name in gridimageadapter is " + name);

             BitmapFactory.Options options = new BitmapFactory.Options();
             Bitmap bitmap = BitmapFactory.decodeFile(name);

             Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, false);
             if(holder.image != null){
                 holder.image.setImageBitmap(newbitmap); 
             }
             bitmap.recycle();

            }
     }
}

所以我的问题是:

so my questions are:

  1. 我怎样写一个SQLite查询返回的行数NOT NULL的列?我目前的执行情况是:

  1. How do i write an sqlite query to return a column with rows not null? my current implementation is:

公开光标retrieveTag(字符串标签){

public Cursor retrieveTag(String tag){

    String[] condition = {KEY_ID,tag};
Cursor cursor = db.query(DATABASE_TABLE, condition, null, null, null, null, null);      
    return cursor;
}

  • 从BindView code,如果我使用这个条件像

  • from the BindView code, if i use this condition like

    如果(!name.equals(空)||!name.equals()){   }

    if( !name.equals(null) || !name.equals("")){ }

    我得到的是一个NullPointerException异常。这是为什么呢?..这是测试字符串的正确方法吗?..

    i get a NullPointerException on the it. Why is that?.. this is the correct way to test for Strings right?..

    希望很清楚我的问题,任何帮助将大大AP preciated。谢谢你。

    Hope am clear in my question and any help will be greatly appreciated. Thank you.

    推荐答案

    通过使用SQL查询,您可以管理数据,而不空值见下文code。

    By using Sql query you can manage the data without null values see below code.

    Cursor c=db.rawQuery("Select columnB from tablename where columnB IS NOT NULL");
    

    这篇关于SQLite的查询检索所有的行不为空的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆