2013-01-04 32 views
0

我对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, 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", "[email protected]", "Scott", "James"); 
AccountVO userAccount2 = new AccountVO("2", "john", "password", "[email protected]", "John", "Smith"); 

我有另一个活动其中I从中我上面创建的对象中检索值和的EditText字段显示它们。假设我更改了字段中的数据并单击“更新”按钮,任何人都可以告诉我如何更新我的旧AccountVO对象中的值?例如:如果我通过“userAccount”AccountVO对象(比如说[email protected])中的edittitext字段更改电子邮件,那么如何更新同一对象中的该值?

回答

1

写二传手每个你有一个getter,像这样的字段:

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

然后,调用二传手在更新功能:

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

如果我们存储AccountVO类'HashMap '中的实例,那么我们很容易更新或替换下一个类的变更对象 –