在DataBase类
中 public boolean checkEvent(String title)
{
ArrayList<String> values = new ArrayList<String>();
values=getValues();
String[] arrBMInfo;
int j=0;
String items[]=title.split(":");
for(int i=0;i<values.size();i++)
{
arrBMInfo=values.get(i).split(":");
if(arrBMInfo[0]==items[0]&&arrBMInfo[1]==items[1])
{
Log.d("Title",arrBMInfo[0]+items[0]+" "+arrBMInfo[1]+items[1]);
j=1;
}
if(j=1)
{
return true;
j=0;
}
else
return false;
}
DataBase类中的getValues方法
public ArrayList<String> getValues()
{
ArrayList<String> values = new ArrayList<String>();
String[] columns = new String[] { KEY_NAME };
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(DATABASE_TABLE, columns, null,
null, null, null, null);
if (cursor .moveToFirst())
{
while (cursor.isAfterLast() == false)
{
String name = cursor.getString(cursor
.getColumnIndex(DataBase.KEY_NAME));
values.add(name);
cursor.moveToNext();
}
}
cursor.close();
db.close();
return values;
}
活动
if(helper.checkEvent(UserName + ":" + Address )==true)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(this,R.style.AlertDialogCustom));
dialog.setTitle("Aler Message");
dialog.setMessage("Record Already Exit");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
dialog.show();
答案 0 :(得分:0)
在比较字符串时使用.equals()
,而不是==
。
if(arrBMInfo[0].equals(items[0]) && arrBMInfo[1].equals(items[1])) {
// etc.
}