如果在android sqlite中使用数据库的条件

时间:2014-01-22 15:55:55

标签: android sqlite

我正在尝试在我的项目中创建一个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;
}

0 个答案:

没有答案