在androidsqlite中使用数据库的If-else条件

在androidsqlite中使用数据库的If-else条件,android,sqlite,Android,Sqlite,我试图在我的项目中创建一个if-else语句,但我不知道如何创建一个else语句,该语句的条件是,如果在编辑文本中输入的条形码编号不是来自数据库,它将显示一条特定的消息……我如何实现这一点?提前谢谢 这也是我的代码行 public void scan (View v){ imageArray.clear(); DatabaseHandler db = new DatabaseHandler(this); EditText barcode= (EditText)findViewById(R.id

我试图在我的项目中创建一个if-else语句,但我不知道如何创建一个else语句,该语句的条件是,如果在编辑文本中输入的条形码编号不是来自数据库,它将显示一条特定的消息……我如何实现这一点?提前谢谢

这也是我的代码行

public void scan (View v){

imageArray.clear();
DatabaseHandler db = new DatabaseHandler(this);
EditText barcode= (EditText)findViewById(R.id.editText2);
String barcodenum;
barcodenum=barcode.getText().toString();

if (barcodenum.equals("")){
    Toast.makeText(Cart.this, "You've entered an empty barcode number",Toast.LENGTH_SHORT).show();
}
else if (barcodenum!=){ //This is the line im talking about
    Toast.makeText(Cart.this, "The barcode you've entered doesn't exist",Toast.LENGTH_SHORT).show();
}
else if (barcodenum!=null){
    Toast.makeText(Cart.this, "Showing the item you've searched!",Toast.LENGTH_SHORT).show();


barcode.setText("");
ImageView front=(ImageView)findViewById(R.id.imageView1);
front.setVisibility(View.INVISIBLE);
imageArray.add(db.getItems(Integer.valueOf(barcodenum)));
adapter1=new ItemImageAdapter(this,R.layout.soloitem,imageArray);
gridView.setAdapter(adapter1);

goback();

ImageButton btnGoBack=(ImageButton)findViewById(R.id.btnBack);
btnGoBack.setVisibility(View.VISIBLE);

MakeItemsInvisible();
}
下面是getItems的DatabaseHandler

 Items getItems(int id) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(TBL_ITEMS, new String[] {ITEM_ID, ITEM_BARCODE ,ITEM_NAME,
            ITEM_PRICE ,ITEM_CATEGORY, ITEM_IMG, ITEM_CLICKED }, ITEM_BARCODE + "=?",
            new String[] { String.valueOf(id) }, null, null, null, null );
    if (cursor != null)
        cursor.moveToFirst();
    Items items = new Items(Integer.parseInt(cursor.getString(0)),Integer.parseInt(cursor.getString(1)),
            cursor.getString(2),Float.parseFloat(cursor.getString(3))
            ,cursor.getString(4),cursor.getBlob(5),Integer.parseInt(cursor.getString(6)));

    // return item
    return items;
}

你为什么不直接查询数据库,看看输入的条形码编号是否存在?@katzoft我对此感到困惑……你能做一个样本吗?我没有数据库处理程序的代码,但我假设类似db.getItems(Integer.valueOf(barcodenum)).count()的代码==0就可以了。@katzoft我已经为db.getItems添加了我的DatabaseHandler,你能看一下吗?非常感谢你的帮助我越来越棒了ideas@katzoft我尝试使用else if(db.getItems(Integer.valueOf(barcodenum)).count()==0),但它给了我一些错误。