1

是否可以附加我存储的数据SharedPreferences而不是覆盖每个条目?

public void onClick(View argument) {
    // TODO Auto-generated method stub

    if(argument==save)
    {
        SharedPreferences sp=getSharedPreferences("userInfo", 0);
        SharedPreferences.Editor spe=sp.edit();
    spe.putInt("ID",Integer.parseInt(enteredID.getText().toString()));
        spe.putString("name", enteredName.getText().toString());
        spe.putString("password",enteredPassWord.getText().toString());
        spe.putInt("age", Integer.parseInt(enteredAge.getText().toString()));

        spe.commit();
        }   

} 
4

1 回答 1

0

获取您放入 SharedPreferences 中的最后一个值并与新值连接,例如:

 String prevString = spe.getString ("name", "");
 spe.putString("name", prevString.concat(enteredName.getText().toString()));
于 2013-06-30T10:00:55.670 回答