我有一个名为" UserData"的分类,包含一个列名" usersports"这是一个数组类型,我在该数组中成功添加了值,现在我必须删除所有值,每当我插入一个新条目
login_data.addAllUnique("usersports",selected_sport_list);
其中selected_sport_list
是包含sports的数组列表,login_data
是解析对象
private class SaveUserDataToParse extends AsyncTask<String, String, String> {
private Context context;
private ProgressDialog progressDialog;
public SaveUserDataToParse(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
//Do your loading here
ParseQuery<ParseObject> query = ParseQuery.getQuery(Sportapp.USERDATA);
query.whereEqualTo(Sportapp.USER_GOOGLE_ID, google_id_from_preference.trim());
ParseObject login_data = query.getFirst();
if (login_data != null) {
login_data.put(Sportapp.USER_CITY, User_city);
login_data.put(Sportapp.USER_STATE, User_state);
login_data.put(Sportapp.USER_COUNTRY, User_country);
if(!selected_sport_list.isEmpty()){
login_data.addAllUnique(Sportapp.USER_SPORTS,selected_sport_list);
//login_data.removeAll(Sportapp.USER_SPORTS,selected_sport_list);
}
login_data.saveInBackground();
}
} catch (ParseException e) {
e.printStackTrace();
}
return "finish";
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Your Data has been successfully Saved", Toast.LENGTH_SHORT).show();
}
}
由于我遇到困难,使用上面的代码我可以在解析数组中添加数据。 但是执行这段代码我必须在解析时删除包含数组的数据。
答案 0 :(得分:2)
在代码中删除此行: - login_data.addAllUnique(Sportapp.USER_SPORTS,selected_sport_list);
并添加: - login_data.put(Sportapp.USER_SPORTS,selected_sport_list);