-2
를로드하지 않습니다 여기에 저장하고 데이터를로드하는 데 사용됩니다 내 savaData 및 loadData 방법이다된 SharedPreferences 저장하거나 내 데이터 안드로이드
여기public void saveData(){
SharedPreferences sharedPreferences= getActivity().getSharedPreferences("SubjectTitle", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
int i=0,n;
n=addArray.size();
for(Bunk b: addArray) {
editor.putString("Title"+i, b.getTitle());
editor.putInt("No_of_bunk"+i, b.getBunk_remain());
editor.putFloat("pre_of_att"+i, b.getPrecentageAtt());
i++;
}
editor.putInt("size_of_data",n);
editor.apply();
Toast.makeText(getActivity(),"data saved",Toast.LENGTH_SHORT).show();
}
public ArrayList<Bunk> loadData(){
SharedPreferences sharedPreferences= getActivity().getSharedPreferences("SubjectTitle", Context.MODE_PRIVATE);
int n=sharedPreferences.getInt("size_pf_data",Default);
String loadTitle;
int loadBunk;
float loadAtt;
for(int i=0;i<n;i++){
loadTitle=sharedPreferences.getString("Title"+i,DEFAULT);
loadBunk=sharedPreferences.getInt("No_of_bunk"+i,Default);
loadAtt=sharedPreferences.getFloat("pre_of_att"+i,def_ault);
addArray.add(new Bunk(loadTitle,loadBunk,loadAtt));
}
return addArray;
}
입니다 loadData 방법에서 데이터를로드하는 데 사용되는 코드
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup perent, Bundle savedInstanceState) {
super.onCreateView(inflater, perent, savedInstanceState);
View v = inflater.inflate(R.layout.fragment_main, perent, false);
show=(ListView)v.findViewById(android.R.id.list);
addArray=loadData();
adapter=new BunkAdapter(addArray);
show.setAdapter(adapter);
return v;
}
스택 오버플로에 오신 것을 환영합니다! [둘러보기]를 먼저 듣고 좋은 질문을 배우고 [mcve]를 만들 수 있습니다. 그렇게하면 우리가 당신을 도울 수 있습니다. – Katie