Java 如何更新存储在“上”对象中的值;更新;点击按钮-安卓?

Java 如何更新存储在“上”对象中的值;更新;点击按钮-安卓?,java,android,Java,Android,我有以下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, Str

我有以下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");
我在活动中创建以下对象。

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对象中的EditText字段更改电子邮件(例如scott@abc.com),如何在同一对象中更新该值?

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

public void setLastName(String lastName) {
    this.lastName = lastName;
}
然后,在Update函数中调用setter:

public void Update() { 
    userAccount.setLastName(editText.getText().toString());
}

若我们将AccountVO类实例存储在
HashMap
中,那个么我们就可以轻松地更新或替换下一个类中的changes对象