저는 baseexpandablelistadapter를 작성하고 있습니다. 그 안에, 검색 매개 변수로 전달할 문자열이 필요한 sqlite 쿼리를 실행하고 싶습니다. 이 문자열을 공유 환경 설정에 저장 했으므로 이제이를 검색하려고합니다. 불행히도, 나는 이것을 할 수없는 것 같습니다.baseexpandablelistadapter 내에서 공유 환경 설정 가져 오기
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
ClientSmartFinderSettings child = (ClientSmartFinderSettings) getChild(groupPosition, childPosition);
ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.expandlist_child_item, null);
holder.checkBox = (CheckBox) view.findViewById(R.id.check_box);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
try {
//this is where the error is
SharedPreferences sharedPref = getSharedPreferences("FileName", MODE_PRIVATE);
holder.checkBox.setChecked(child.getIsSelected());
} catch (Exception e) {
}
return view;
}
오류 :
MODE_PRIVATE 변수
에 해결 될 수없는 내가 MODE_PRIVATE는 활동에 적용 할 수 만 보인다 것으로 알고 있습니다. 그렇다면 어떻게하면 기본 확장 가능한 목록 아답터의 내부에서 공유 환경 설정을 검색 할 수 있습니까?
감사합니다. 된 SharedPreferences가에 단 한 번 개체를 내가 만들 것이다, 또한
SharedPreferences sharedPreferences = context.getSharedPreferences("FileName", Context.MODE_PRIVATE);
: 우선
'Context.MODE_PRIVATE' 여야합니다. – hardartcore
제안 해 주셔서 감사합니다. 나는 그것을 시도했다. "메소드 getSharedPreferences (String, int)가 ExpandListAdapter 유형에 대해 정의되지 않았습니다." – Alex
어댑터의 생성자에서 Context 매개 변수를 제공하고 'mContext.getSharedPreferences (String, int);'로 사용해야합니다. – hardartcore