dialogBuilder.setMessage
什么也看不出来!好像它在显示 null
字符串。但是, newUserPassword
使用用户通过edittext提供的较新输入进行更新 newPassword
```
public class OKActivity extends Activity {
EditText newPassword;
String newUserPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ok);
newPassword = (EditText) findViewById(R.id.new_password);
newUserPassword = newPassword.getText().toString();
getpasswordSharedPreferences();
Button changePassword = (Button) findViewById(R.id.button_change);
changePassword.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setSharedPreferences();
}
});
}
private String getpasswordSharedPreferences() {
SharedPreferences userPassword = getSharedPreferences("USER_PASSWORD", MODE_PRIVATE);
String password = userPassword.getString("THE_PASSWORD", "123");
return password;
}
private void setSharedPreferences() {
SharedPreferences userPassword = getSharedPreferences("USER_PASSWORD", MODE_PRIVATE);
SharedPreferences.Editor password_edior = userPassword.edit();
password_edior.putString("THE_PASSWORD", newUserPassword);
password_edior.commit();
Toast.makeText(OKActivity.this, "Password Change Succesful", Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OKActivity.this);
dialogBuilder.setIcon(R.drawable.ic_launcher);
dialogBuilder.setTitle("Done!");
dialogBuilder.setMessage(newUserPassword);
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.show();
}
![](https://i.stack.imgur.com/eDrVp.png)
1条答案
按热度按时间2ekbmq321#
试试这个: