テキストを設定してテキストをプロファイルデータフィールドに設定し、ユーザーの変更や更新を行う前に前の入力のeditTextsに変更します。続いループ内のスイッチを2回実行することはできません
は符号である:
オリジナルデータが文字列である: {K1 = V1、K2 = V2、K3 = V3、... K9 = V9}
public void parse(String foo) {
String foo2 = foo.substring(1, foo.length() - 1); // hack off braces
StringTokenizer st = new StringTokenizer(foo2, ",");
String[] key = new String[20];
String[] value = new String[20];
int i = 0;
while (st.hasMoreTokens()) {
String thisToken = st.nextToken();
String[] keyValue = thisToken.split("=");
try {
key[i] = keyValue[0];
value[i] = keyValue[1];
setTextToFields(key[i], value[i]);
i++;
} catch (Exception e) {
e.printStackTrace();
}
}
//for (i = 0; key[i] != null && value[i] != null && i <= 9; i++) {
// setTextToFields(key[i], value[i]);
//}
そして私はこのsetTextToFields方法の第2回以上呼び出されると、
public void setTextToFields(String key, String value) {
String dateOfBirth = null;
switch (key) {
case "dateOfBirth":
dateOfBirth = value;
try {
etYear.setText(dateOfBirth.substring(0, 4), TextView.BufferType.EDITABLE);
etMonth.setText(dateOfBirth.substring(5, 7), TextView.BufferType.EDITABLE);
etDay.setText(dateOfBirth.substring(8), TextView.BufferType.EDITABLE);
} catch (Exception e) {
e.printStackTrace();
}
return;
case "firstName":
etFirstName.setText(value, TextView.BufferType.EDITABLE);
return;
case "lastName":
etLastName.setText(value, TextView.BufferType.EDITABLE);
return;
case "country":
etCountry.setText(value, TextView.BufferType.EDITABLE);
return;
case "city":
etCity.setText(value, TextView.BufferType.EDITABLE);
return;
case "iDNumber":
etIDNumber.setText(value, TextView.BufferType.EDITABLE);
return;
case "postCode":
etPostCode.setText(value, TextView.BufferType.EDITABLE);
return;
case "mobilePhoneNumber":
etMobilePhoneNumber.setText(value, TextView.BufferType.EDITABLE);
return;
case "province":
etProvince.setText(value, TextView.BufferType.EDITABLE);
return;
case "address":
etAddress.setText(value, TextView.BufferType.EDITABLE);
return;
default:
Toast.makeText(ProfileActivity.this,"Nothing set to text", Toast.LENGTH_SHORT).show();
return;
}
スイッチは、デフォルトに選択し、editTに何も設定していない:私は次のように、テキストを設定するにはsetTextToFieldsメソッドを呼び出しextビュー。
理由を教えてください。
私はそうではないと言います。あなたは[mcve]を投稿できますか? –
申し訳ありませんが、何を意味するのか分かりません。 –