我有一个Android应用程序的以下类。
public class AccountVO
{
private String id;
private String username;
private String password;
private String email;
private String firstName;
private String lastName;
public AccountVO(String tempID, String tempUserName, String tempPassword, String tempEmail, String tempFirstName, String tempLastName)
{
this.id = tempID;
this.username = tempUserName;
this.password = tempPassword;
this.email = tempEmail;
this.firstName = tempFirstName;
this.lastName = tempLastName;
}
public String getId()
{
return id;
}
public String getUserName()
{
return username;
}
public String getEmail()
{
return email;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
}
我在活动中创建了以下对象。
AccountVO userAccount = new AccountVO("1", "scott", "password", "scott@mail.com", "Scott", "James");
AccountVO userAccount2 = new AccountVO("2", "john", "password", "jsmith@mail.com", "John", "Smith");
我有另一个活动,我从上面创建的对象中检索值并在EditText字段中显示它们。假设我更改字段中的数据并单击“更新”按钮,任何人都可以告诉我如何更新旧的AccountVO对象中的值?例如:如果我通过“userAccount”AccountVO对象(例如scott@abc.com)中的edittitext字段更改电子邮件,如何在同一对象中更新该值?
答案 0 :(得分:1)
为你有getter的每个字段写一个setter,如下所示:
public void setLastName(String lastName) {
this.lastName = lastName;
}
然后,在Update函数中调用setter:
public void Update() {
userAccount.setLastName(editText.getText().toString());
}