我想要android中的行数

时间:2014-11-27 07:52:24

标签: android cursor

我正在使用cursor.getcount但它不工作我很困惑。我试图从给定日期的标签中获取数据,但它不起作用。

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            date=et.getText().toString();

            cursor= db.rawQuery("Select count(*) from labels where date='" + date + "'", null);
            //  db.openDatabase(path, factory, flags)
            //  Log.d("Query", "Select count(*) from labels where date='" + date + "'");


            //Log.d("cursor Length", )
            if(cursor!=null && cursor.getCount()>0)
            {
                cursor.moveToFirst();
                Toast.makeText(getApplicationContext(), "Already Exist", Toast.LENGTH_SHORT).show();


            }
            else{

                Toast.makeText(getApplicationContext(), "Please Download Latest Data", Toast.LENGTH_SHORT).show();
                return;
            }
        }

1 个答案:

答案 0 :(得分:0)

将您的查询更改为

"Select count(*)AS count from labels where date='" + date + "'"

将此if(cursor!=null && cursor.getCount()>0)替换为

if(cursor!=null && cursor.getInt(cursor.getColumnIndex("count"))>0)

或者以其他方式,您只需将查询更改为

即可
"Select * from labels where date='" + date + "'"

,您的其他代码将与您完成的工作相同。

相关问题