0

我有以下用于 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 字段更改电子邮件,如何在同一对象中更新该值?

4

1 回答 1

1

为您拥有 getter 的每个字段编写一个 setter,如下所示:

public void setLastName(String lastName) {
    this.lastName = lastName;
}

然后,在 Update 函数中调用 setter:

public void Update() { 
    userAccount.setLastName(editText.getText().toString());
}
于 2013-01-04T18:47:40.813 回答