我有一个 ArrayAdapter,我需要获取应用程序的共享首选项才能对其进行处理。我的问题是我无法获得共享偏好。那是我的代码:
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
private static SharedPreferences prefs;
private String firstBtName = "";
private String secondBtName = "";
private String thirdBtName = "";
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.list, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
prefs = getSharedPreferences("MYPREFS", 0); // ERROR **************
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
textView.setText(values[position]);
eclips 说我没有那种方法……我该怎么办?谢谢!