사용자가 프로필에서 표시 이름을 변경할 때 공유 기본 설정을 다시 저장하고 싶습니다.
이제 데이터베이스의 데이터가 변경되었지만 공유 기본 설정을 변경하는 방법을 모르겠습니다.
도와주세요, 제발.
암호:
private static final String PREFERENCE_KEY = "pref_user";
private static final String DISPLAY_KEY = "user_display_name";
SharedPreferences sh_pref;
SharedPreferences.Editor sh_edit;
UserPreference setting;
private int user_id;
private String getuser_id;
private String user_display_name;
EditText EDTEditdisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_change_displayname);
// custom my action bar
ActionBar actionbar = getActionBar();
actionbar .setTitle("CHANGE DISPLAY NAME");
// back navigation
actionbar.setDisplayHomeAsUpEnabled(true);
// hide icon app
getActionBar().setDisplayShowHomeEnabled(false);
setting = new UserPreference(ChangeDisplayNameActivity.this);
user_id = setting.getUserID();
getuser_id = String.valueOf(user_id);
Button BTNsaveDisplayname = (Button) findViewById(R.id.BTNsaveDisplayname);
BTNsaveDisplayname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UpdateDisplayName();
}
});
}//end onCreate
public boolean UpdateDisplayName() {
EDTEditdisplay = (EditText) findViewById(R.id.EDTEditdisplay);
// Dialog alert
AlertDialog.Builder alert = new AlertDialog.Builder(this);
// Check Displayname
if(EDTEditdisplay.getText().length() == 0)
{
alert.setMessage("Please input new display name");
alert.show();
EDTEditdisplay.requestFocus();
return false;
}
// gettext from edittext
user_display_name = EDTEditdisplay.getText().toString();
List<NameValuePair> update_display = new ArrayList<NameValuePair>();
update_display.add(new BasicNameValuePair("user_id", getuser_id));
update_display.add(new BasicNameValuePair("user_display_name", user_display_name));
JSONParser jspaser = new JSONParser();
String url = "http://su13540254.2th.asia/Hello_Oppa/update_displayname.php";
String dataJSON = jspaser.makeHttpRequest(url,JSONParser.methodPost, update_display);
Toast.makeText(getApplicationContext(),
"Change display name, Complete", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ChangeDisplayNameActivity.this, MainActivity.class);
startActivity(intent);
return true;
}//end UpdateDisplayName
데이터베이스에 표시 이름을 저장 한 후 동일한 키로 공유 기본 설정을 저장하는 위치에 해당 코드를 다시 넣으면 공유 기본 설정에서 표시 이름이 대체됩니다. 예. 저장하려면 :
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mPreferences.edit().putString("DISPLAY_NAME",user_display_name).commit();
검색하려면 :
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String display_name = mPreferences.getString("DISPLAY_NAME","Default Name");
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다