public class NavigationDrawerFragment extends Fragment {
public static final String PREF_FILE_NAME="testpref";
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLyout;
private boolean mUserLearnedDrawer;
private boolean mFromSavedInstanceState;
public NavigationDrawerFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
}
public void setUp(DrawerLayout drawerLayout,Toolbar toolbar) {
mDrawerLyout=drawerLayout;
mDrawerToggle=new ActionBarDrawerToggle(getActivity(),drawerLayout,toolbar,R.string.drawer_open,R.string.drawer_close){
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
mDrawerLyout.setDrawerListener(mDrawerToggle);
}
public void saveToPreferences(Context context, String preferenceName, String preferenceValue)
{
SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor=SharedPreferences.edit();
editor.putString(preferenceName, preferenceValue);
editor.commit();
}
所以我有錯誤就行, SharedPreferences.Editor編輯= SharedPreferences被引用。 edit();
Error:non static method 'edit' cannot be referenced in static context
非常感謝!是啊,我看到了那個錯誤... –
@AsadKhan如果它可以幫助你接受答案 – Rajesh