0
SharedPreferences와 관련하여 몇 가지 코드를 작성했습니다. 두 개의 버튼을 사용하여 데이터를 저장 및로드하고 저장하고로드합니다. 두 함수는 잘 작동하지만 응용 프로그램을 종료하고 돌아가서로드 버튼을 누르면 이전에 저장된 배열을로드하고이 배열을 listview에로드합니다. 그러나 listview를 클릭하면 문자열이 배열에서 내가 가진 활동을 수행 할 수없는 것 같습니다.SharedPreferences, listview에 대해 알아볼 수없는 호출 된 문자열
누구든지이 문제를 만나고 만나요?
final Button a = (Button) findViewById(R.id.save);
a.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
int mode= MODE_PRIVATE;
// get the sharedPreference of your context.
SharedPreferences mySharedPreferences ; mySharedPreferences=getSharedPreferences("shared",MODE_PRIVATE);
// retrieve an editor to modify the shared preferences
SharedPreferences.Editor editor= mySharedPreferences.edit();
/* now store your primitive type values. In this case it is true, 1f and Hello! World */
for (String s : global.ItemArray){
editor.putString("share", s);
}
//save the changes that you made
editor.commit();
Toast.makeText(getBaseContext(), "Favourites saved", Toast.LENGTH_SHORT)
.show();
}
});
final Button b = (Button) findViewById(R.id.load);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
global.ItemArray.clear();
int mode = Activity.MODE_PRIVATE;
SharedPreferences mySharedPreferences ;
mySharedPreferences=getSharedPreferences("shared", MODE_PRIVATE);
// Retrieve the saved values.
String mSstring = null;
mSstring= mySharedPreferences.getString("share", mSstring);
/*if (mSstring == "1"){
global.ItemArray.add("Introduction To BCLS");
}*/
global.ItemArray.add(mSstring);
Toast.makeText(getBaseContext(), "Favourites loaded", Toast.LENGTH_SHORT)
.show();
lv1.setAdapter(arrad);
}
}
);
모든 값을 가진 올바른'global.ItemArray'를로드 할 수 있습니까? – havexz
"하지만 listview를 클릭하면 배열의 문자열이 내가 가진 활동을 수행 할 수없는 것으로 보입니다." 이 부분의 의미를 설명해 주시겠습니까? –
정상입니다. 이 전역 배열 "global.ItemArray"문자열을 추가하고 목록보기, – PudgeLover