我正在写一个baseexpandablelistadapter。在其中,我想执行一个 sqlite 查询,为此我需要一个字符串作为搜索参数传递。我已将此字符串存储在共享首选项中,现在我想检索它。不幸的是,我似乎无法做到这一点。
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 似乎仅适用于活动。但是,我如何在我的 baseexpandablelistadapter 中检索这个共享偏好?
谢谢!