我通過JSONarray檢索一些聯繫人的一些電話和電子郵件,爲這些元素中的每一個創建一個新的EditText(使用電話或電子郵件)。如果EditText內容更改,如何更新JSONobject?
我想知道如何更新我的JSONobject,如果用戶更改電話號碼或電子郵件,之後我想將此JSON對象添加到JSON數組發佈到我的服務。
這就是我把元素的EditText的代碼:我嘗試一些代碼以「setOnFocusChangeListener」,但它並沒有:-(
在此先感謝工作
try {
multiplesArray = new JSONArray(multiples);
//multiplesUpdatedArray = new JSONArray();
System.out.println(multiplesArray.toString(2));
for (int i=0; i<multiplesArray.length(); i++) {
JSONObject contact = new JSONObject();
String type = multiplesArray.getJSONObject(i).getString("tipo");
String data = multiplesArray.getJSONObject(i).getString("texto");
String id = multiplesArray.getJSONObject(i).getString("id");
if (type.equals("phone")) {
final EditText etPhoneItem = new EditText(this);
etPhoneItem.setText(data);
viewPhonesContainer.addView(etPhoneItem);
} else if (type.equals("email")) {
final EditText etEmailItem = new EditText(this);
etEmailItem.setText(data);
viewEmailContainer.addView(etEmailItem);
}
contact.put("tipo", type);
contact.put("id", id);
contact.put("texto", data);
contact.put("cat", "");
contact.put("cat_id", "");
/*multiplesUpdatedArray.put("tipo");
multiplesUpdatedArray.put(type);
multiplesUpdatedArray.put("id");
multiplesUpdatedArray.put(id);
multiplesUpdatedArray.put("texto");
multiplesUpdatedArray.put(data);*/
}
} catch (JSONException e) {
e.printStackTrace();
}