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();
}
}
So i am having error on the line, SharedPreferences.Editor editor=SharedPreferences.edit();
Error:non static method 'edit' cannot be referenced in static context
Try
SharedPreferences.Editor editor=sharedPreferences.edit();
instead of
SharedPreferences.Editor editor=SharedPreferences.edit();
You can not directly SharedPreferences.edit();
.
You have to create object of SharedPreferences
and You have created which is sharedPreferences
so use it to call edit()
method.
I hope it helps!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments