2013-01-19 3 views
0

사용자가 세부 정보를 입력하고 영구 저장되는 세부 정보 화면이 필요한 작은 프로젝트를 진행 중입니다. 사용자는 세부 사항을 변경해야하는 경우 변경해야하는 옵션이 있어야합니다. 저장 한 환경 설정 라이브러리를 살펴 보았지만 그런 기능을 제공하지는 않습니다. Android 세부 정보 저장 화면

이 필요한 사항을 시각적 아이디어를 제공하기 위해,이 화면 같은 괜찮을해야합니다

http://www.google.com.mt/imgres?start=97&num=10&hl=en&tbo=d&biw=1366&bih=643&tbm=isch&tbnid=aQSZz782gIfOeM:&imgrefurl=http://andrejusb.blogspot.com/2011/10/iphone-web-application-development-with.html&docid=YpPF3-T8zLGOAM&imgurl=http://2.bp.blogspot.com/-YRISJXXajD0/Tq2KTpcqWiI/AAAAAAAAFiE/-aJen8IuVRM/s1600/7.png&w=365&h=712&ei=rbX6ULTDCOfV4gTroIDoCg&zoom=1&iact=hc&vpx=834&vpy=218&dur=2075&hovh=314&hovw=161&tx=80&ty=216&sig=108811856681773622351&page=4&tbnh=155&tbnw=79&ndsp=35&ved=1t:429,r:4,s:100,i:16

어떤 도움을 많이 감사합니다. 미리 감사드립니다.

답변

1

SharedPreferences을 사용하면 지속적으로 저장하려는 소량의 데이터에 적합합니다.

// You can equally use KEY_LAST_NAME to get the last name, etc. They are just key/value pairs 
// Note that the 2nd arg is simply the default value if there is no key/value mapping 
String firstName = prefs.getString(KEY_FIRST_NAME_CONSTANT, ""); 

을 또는 저장하기 :

// 'this' is simply your Application Context, so you can access this nearly anywhere 
SharedPreferences prefs = this.getSharedPreferences(
    "com.example.app", Context.MODE_PRIVATE); 

환경 설정에서 구하려면

Editor editor = prefs.edit(); 
// firstName being the text they entered in the EditText 
editor.putString(KEY_FIRST_NAME_CONSTANT, firstName); 
editor.commit(); 
2

사용자 정보를 저장하는 데 쉽게 Shared Preferences을 사용할 수 있습니다. 환경 설정 화면이 열릴 때마다 저장된 데이터를 공유 환경 설정에서 추출하고 편집을 위해 사용자에게 제공 할 수 있습니다. 편집이 완료되면 공유 환경 설정에서 새 데이터를 다시 업데이트 할 수 있습니다.

또한 수행 할 수있는 방법을 보려면 this 스레드를보십시오.

1

당신은 안드로이드에 SharedPreferences 클래스를 사용하여 이러한 기능을 달성 할 수있다.

public void onCreate(Bundle object){ 
      super.onCreate(object); 
      // Initialize UI and link xml data to java view objects 
       ...... 
       SharedPreferences myPref = getPreferences(MODE_PRIVATE); 
       nameView.setText(myPref.getString("USER_NAME", null)); 
       passView.setText(myPref.getString("PASSWORD", null)); 

     } 
public void onStop(){ 
      super.onStop(); 
      if (isFinishing()) { 

      getPreferences(MODE_PRIVATE).edit() 
      .putString("USER_NAME", nameView.getText().toString()) 
      .putString("PASSWORD", passView.getText().toString()) 
      .commit() 

      } 
}