日安,所以我有一个程序,用户将扫描二维码并在SQLite数据库中获得它的值,但在我获得值之前,弹出一个对话框,告诉我“没有找到参与者”。下面是我的代码:
这是我的onStart覆盖。
@Override
protected void onStart()
{
super.onStart();
getparticipantid = tvParticipantID.getText().toString();
etparticipantidvalue.setText(getparticipantid);
getParticipantIbeam();
}这是我的活动,一旦用户扫描二维码,它将从数据库加载数据。
private void getParticipantIbeam()
{
SQLiteFunctionUlitity.GameIBeamParticipant memberInfo = SQLiteFunctionUlitity.getparticipantIbeam(getparticipantid, mDbHelper.getSqliteObjectWithReadable());
if (memberInfo != null)
{
tvParticipantName.setText(memberInfo.getParticipantName());
tvParticipantNation.setText(memberInfo.getParticipant_nationality());
tvParticipantCategory.setText(memberInfo.getCategory());
tvWave.setText(memberInfo.getWave_number());
tvCategory.setText(memberInfo.getCategory());
}
else
{
Context context = this;
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("No Participant found in the Game.");
builder1.setCancelable(true);
builder1.setPositiveButton("Scan Again", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
Intent intent = new Intent(GameiBeamLineTracing.this, ScanGameIbeam.class);
startActivity(intent);
finish();
}
});
builder1.setNegativeButton("Close", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
onStop();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
}如您所见,我在onStart方法中调用了getParticipantIbeam活动,但是当我调用它时,它读取的是else语句,而不是if语句。
我知道这是一个简单的if else语句和生命周期,但我非常想知道答案。
发布于 2018-07-20 15:36:03
我用过这个库来扫描二维码,它很简单,可能会对你有帮助。
QR Code implementation library for android, Click here (blikoon)
当然,这个库将解决所有与QR Code相关的问题,并且不要忘记实现运行时权限,如照片、图库等。
https://stackoverflow.com/questions/51436798
复制相似问题