【发布时间】:2019-09-24 07:00:31
【问题描述】:
我的要求是,
我有 1 号预告片和电影名称。现在,一旦我在表中插入数据,我需要将文本更改为 Trailer Number 2,直到 Trailer Number 5。因为只插入 5 个数据。此外,我将检查 Trailer Number 1 是否已经存在于表中。如果不存在,我在表格中插入,但如果存在,我将文本更改为 Trailer Number 2。这是它应该工作的确切场景。
但就我而言,当我插入第 1 号预告片时,它会跳转到第 5 号预告片,而不是不显示第 2 号预告片。
点击按钮后
boolean isFirstTrailerNumberExist = myDb.isExist("Trailer Number 1");
boolean isSecondTrailerNumberExist = myDb.isExist("Trailer Number 2");
boolean isThirdTrailerNumberExist = myDb.isExist("Trailer Number 3");
boolean isFourthTrailerNumberExist = myDb.isExist("Trailer Number 4");
boolean isFifthTrailerNumberExist = myDb.isExist("Trailer Number 5");
if(isFirstTrailerNumberExist) {
Toast.makeText(this, "Trailer Number 1 already Exist", Toast.LENGTH_SHORT)
.show();
} else {
boolean isInserted = myDb.insertData(trailerNumberName.getText().toString(),
trailerNumberCount.getText().toString());
if(isInserted){
Toast.makeText(TrailerNumberActivity.this,"Inserted successfully",Toast.LENGTH_SHORT)
.show();
trailerNumberName.setText("Trailer Number 2");
}
else{
Toast.makeText(TrailerNumberActivity.this,"Insertion failed",Toast.LENGTH_SHORT)
.show();
}
}
if(isSecondTrailerNumberExist){
Toast.makeText(this,"Trailer Number 2 already Exist",Toast.LENGTH_SHORT)
.show();
}
else {
boolean isInserted = myDb.insertData(trailerNumberName.getText().toString(),
trailerNumberCount.getText().toString());
if(isInserted){
Toast.makeText(TrailerNumberActivity.this,"Inserted successfully",Toast.LENGTH_SHORT)
.show();
trailerNumberName.setText("Trailer Number 3");
}
else{
Toast.makeText(TrailerNumberActivity.this,"Insertion failed",Toast.LENGTH_SHORT)
.show();
}
}
//the same repeats for third, fourth and fifth trailer too to check in db
if(isThirdTrailerNumberExist){
Toast.makeText(this,"Trailer Number 3 already Exist",Toast.LENGTH_SHORT)
.show();
}
else {
boolean isInserted = myDb.insertData(trailerNumberName.getText().toString(),
trailerNumberCount.getText().toString());
if(isInserted){
Toast.makeText(TrailerNumberActivity.this,"Inserted successfully",Toast.LENGTH_SHORT)
.show();
trailerNumberName.setText("Trailer Number 4");
}
else{
Toast.makeText(TrailerNumberActivity.this,"Insertion failed",Toast.LENGTH_SHORT)
.show();
}
}
if(isFourthTrailerNumberExist){
Toast.makeText(this,"Trailer Number 4 already Exist",Toast.LENGTH_SHORT)
.show();
}
else {
boolean isInserted = myDb.insertData(trailerNumberName.getText().toString(),
trailerNumberCount.getText().toString());
if(isInserted){
Toast.makeText(TrailerNumberActivity.this,"Inserted successfully",Toast.LENGTH_SHORT)
.show();
trailerNumberName.setText("Trailer Number 5");
}
else{
Toast.makeText(TrailerNumberActivity.this,"Insertion failed",Toast.LENGTH_SHORT)
.show();
}
}
if(isFifthTrailerNumberExist){
Toast.makeText(this,"Trailer Number 5 already Exist",Toast.LENGTH_SHORT)
.show();
}
else {
boolean isInserted = myDb.insertData(trailerNumberName.getText().toString(),
trailerNumberCount.getText().toString());
if(isInserted){
Toast.makeText(TrailerNumberActivity.this,"Inserted successfully",Toast.LENGTH_SHORT)
.show();
trailerNumberName.setText("Trailer Number 1");
}
else{
Toast.makeText(TrailerNumberActivity.this,"Insertion failed",Toast.LENGTH_SHORT)
.show();
}
}
这就是我重复显示直到预告片 5 的方式,但问题是在插入预告片 1 后,它会跳转到预告片 5。
【问题讨论】:
标签: java android database if-statement android-sqlite