项目一次又一次地保存在 sqlite 数据库中
Item is Saving in sqlite database again and again
我试图仅在满足所需条件时才在 sqlite 数据库中保存一个值,但即使满足条件并且它不会停止,它也会在数据库中保存该值。
这是我的代码
int asas = 0;
if (list!= null) {
for (int i1 = 0; i1 < list.size(); i1++) {
String s= list.get(i1);
while (msgBody.toUpperCase().contains(s.toUpperCase()) && !contactExists(context, msg_from)) {
asas++;
if (asas>=3)
{
screenMessage(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
if (asas <3 && !contactExists(context, msg_from)) {
screenMessagee(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
break;
}
break;
}
}
}
现在让我解释一下我的代码。我有一个列表视图,其中包含存储在其中的不同项目。现在我在这里做的是检查用户给出的名为 "msgBody" 的字符串是否包含存储的列表视图项。这就是为什么我使用 int asas=0 以便当用户给出字符串时 while 条件检查用户提供的字符串中该列表视图中有多少项。如果字符串包含 3 个或更多项,则将其保存在特定 table 中。如果字符串包含少于 3 个项目,则将其保存在另一个 table 中。
现在我面临的问题是,如果提供的字符串包含 lets example 5 项,那么提供的字符串将在此 table 中保存 3 次
screenMessage(context, msg_from, msg_from, msgBody, msgDate);
我发现这可能会发生,因为当条件达到存储的 3 个项目时,它会将值保存在数据库中,但是由于提供的字符串包含 5 个项目,所以当条件不会停止并再次保存该值两次时直到所有 5 个项目都满足条件。
如果找到 3 个项目并且值必须在数据库中仅保存一次,请帮助如何停止这种情况 table
据我了解,您想计算存储在列表中的单词在特定字符串中出现的次数,然后将其存储在两个数据库表之一中,具体取决于它是否小于 3。
我不太理解你的代码,但试试这个:
int asas = 0;
if (list!= null) {
for (int i1 = 0; i1 < list.size(); i1++) {
String s= list.get(i1);
if(msgBody.toUpperCase().contains(s.toUpperCase()) && !contactExists(context, msg_from)){
asas++;
}
}
if(asas>0){
if(asas<3)
{
screenMessagee(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
else{
screenMessage(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
}
我试图仅在满足所需条件时才在 sqlite 数据库中保存一个值,但即使满足条件并且它不会停止,它也会在数据库中保存该值。
这是我的代码
int asas = 0;
if (list!= null) {
for (int i1 = 0; i1 < list.size(); i1++) {
String s= list.get(i1);
while (msgBody.toUpperCase().contains(s.toUpperCase()) && !contactExists(context, msg_from)) {
asas++;
if (asas>=3)
{
screenMessage(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
if (asas <3 && !contactExists(context, msg_from)) {
screenMessagee(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
break;
}
break;
}
}
}
现在让我解释一下我的代码。我有一个列表视图,其中包含存储在其中的不同项目。现在我在这里做的是检查用户给出的名为 "msgBody" 的字符串是否包含存储的列表视图项。这就是为什么我使用 int asas=0 以便当用户给出字符串时 while 条件检查用户提供的字符串中该列表视图中有多少项。如果字符串包含 3 个或更多项,则将其保存在特定 table 中。如果字符串包含少于 3 个项目,则将其保存在另一个 table 中。 现在我面临的问题是,如果提供的字符串包含 lets example 5 项,那么提供的字符串将在此 table 中保存 3 次
screenMessage(context, msg_from, msg_from, msgBody, msgDate);
我发现这可能会发生,因为当条件达到存储的 3 个项目时,它会将值保存在数据库中,但是由于提供的字符串包含 5 个项目,所以当条件不会停止并再次保存该值两次时直到所有 5 个项目都满足条件。 如果找到 3 个项目并且值必须在数据库中仅保存一次,请帮助如何停止这种情况 table
据我了解,您想计算存储在列表中的单词在特定字符串中出现的次数,然后将其存储在两个数据库表之一中,具体取决于它是否小于 3。
我不太理解你的代码,但试试这个:
int asas = 0;
if (list!= null) {
for (int i1 = 0; i1 < list.size(); i1++) {
String s= list.get(i1);
if(msgBody.toUpperCase().contains(s.toUpperCase()) && !contactExists(context, msg_from)){
asas++;
}
}
if(asas>0){
if(asas<3)
{
screenMessagee(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
else{
screenMessage(context, msg_from, msg_from, msgBody, msgDate); //saving value in this table
}
}