我的Android代码存在问题,我正在使用SDK从Dynamodb读取我想使用getItem读取一个Item,但是如果找到Item,我想要做一个Toast msg" Item被发现"如果没有找到吐司信息"没有找到任何项目。在DynamoDBManager类中,文件是可以的,我需要在我的Activity类中获取该信息
public static WinTicket getTicketByBarcode(String barcodeNumber) {
AmazonDynamoDBClient ddb = Barca.clientManager.ddb();
DynamoDBMapper mapper = new DynamoDBMapper(ddb);
try {
WinTicket winTicket = mapper.load(WinTicket.class,
barcodeNumber);
if(winTicket == null){
String awo = "false" ;
Log.e(TAG,"NOT FOUND");
// No item found
}
else{
String awo = "true" ;
Log.e(TAG,"YES FILE IN DATABASE");
// Item is found in database
}
return winTicket;
} catch (AmazonServiceException ex) {
Barca.clientManager.wipeCredentialsOnAuthError(ex);
}
return null;
}
上面的代码是DynamodbManager类
这里的人来自Barca Activity课程 我认为在Activity文件中我需要做一些编辑我不知道但是我确定它在私有类DynamoDBManagerTask或protected void onPostExecute
private class DynamoDBManagerTask extends
AsyncTask<DynamoDBManagerType, Void, DynamoDBManagerTaskResult> {
protected DynamoDBManagerTaskResult doInBackground(
DynamoDBManagerType... types) {
DynamoDBManagerTaskResult result = new DynamoDBManagerTaskResult();
result.setTaskType(types[0]);
if (types[0] == DynamoDBManagerType.GET_BARCODE) {
user = DynamoDBManager.getTicketByBarcode(winnum);
Log.e(TAG,winnum);
}
return result;
}
protected void onPostExecute(DynamoDBManagerTaskResult result) {
// pdia.dismiss();
if (result.getTaskType() == DynamoDBManagerType.GET_BARCODE) {
if (datafound.equalsIgnoreCase("true")) {
Log.e(TAG,datafound);
Toast.makeText(Barca.this, "Item found",
Toast.LENGTH_SHORT).show();
}
else if (datafound.equalsIgnoreCase("false")){
Log.e(TAG,datafound);
Toast.makeText(
Barca.this,
"Sorry no Item found",
Toast.LENGTH_SHORT).show();
}
}
}
}
答案 0 :(得分:1)
我必须在protected void onPostExecute(DynamoDBManagerTaskResult result)部分使用和if语句
if user == null {
//item not in database
}
else {
// item in database
}