我正在开发一款应用程序,我想用旧值更新新值,但是当我尝试更新时,它也会再次显示旧值。我有行数组中的字符串数组,我想在我的应用程序中用新值更新这个字符串数组,我必须在应用程序中用新值显示旧值。但在我的代码中,我显示更新,但它重复旧值?我如何解决这个问题?我在做这个操作的活动中导航。如何使用android更新sqlite表中的行项?
例如:我有字符串数组等
str1[] str1= {"1","2","3","4"};
str2[] str2= {"a", "b","c","d"};
现在我有像
str1[] str1= {"1","2","3","4","6", "8"};
str2[] str2= {"a", "b","c","d", "j", "l"};
和我的输出显示在当前的代码用新值来更新这是
str1[] str1= {"6", "8","1","2","3","4","1","2","3","4"};
str2[] str2= {"j", "l","a", "b","c","d", "a", "b","c","d"};
代码
// list values
private void checkButtonClick() {
ArrayList<String> list1= new ArrayList<>();
ArrayList<String> list2= new ArrayList<>();
Poses country = null;
ArrayList<Poses> countryList = dataAdapter.countryList;
for (int i = 0; i < countryList.size(); i++) {
country = countryList.get(i);
if (country.isSelected()) {
// responseText.append("\n" + country.getName());
list1.add(country.getName());
list1.add(convertArrayToString(subject));
list2.add(country.getCode());
list2.add(convertArrayToString(spinner));
}
}
final String [] names = list1.toArray(new String[list1.size()]);
final String [] spinner = list2.toArray(new String[list2.size()]);
dbManager.update(id1, names, spinner);
}
//db values query
public int update(long _id, String [] selected_pgm, String [] spinner_value) {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.SELECTED, convertArrayToString(selected_pgm));
contentValues.put(DatabaseHelper.SPINNER, convertArrayToString(spinner_value));
int i = database.update(DatabaseHelper.TABLE_NAME, contentValues, DatabaseHelper._ID + " = " + _id, null);
return i;
}
前项添加到列表中,首先清除它们。 'list1.clear()'和'list2.clear()' –
@JohnJoe我想做但它清除所有记录的列表 – Rohu