Skip to main content

Shared Preference Common Class

public class SessionSave {

   public static void saveSession(String key, String value , Context context){
      Editor editor = context.getSharedPreferences("KEY", Activity.MODE_PRIVATE).edit();
      editor.putString(key, value);
      editor.commit();
   }
   
   public static String getSession(String key,Context context){
      SharedPreferences prefs = context.getSharedPreferences("KEY", Activity.MODE_PRIVATE);
      return prefs.getString(key, "");
   }
   
   public static void clearSession(Context context){
      Editor editor = context.getSharedPreferences("KEY", Activity.MODE_PRIVATE).edit();
      editor.clear();
      editor.commit();
   }
   
   public static void tutorialChk(boolean isAsk,Context con)
   {
      Editor editor=con.getSharedPreferences("ASK", Context.MODE_PRIVATE).edit();
      editor.putBoolean("isAsk", isAsk);
      editor.commit();
   }
   
   public static boolean isAsk(Context con)
   {
      SharedPreferences sharedPreferences=con.getSharedPreferences("ASK", Context.MODE_PRIVATE);
      return sharedPreferences.getBoolean("isAsk",false);
      
   }

   // INTEGER   public static void saveIntSession(String key, int value, Context context) {
      Editor editor = context.getSharedPreferences("KEY_INTEGER", Activity.MODE_PRIVATE).edit();
      editor.putInt(key, value);
      editor.commit();
   }

   public static int getIntSession(String key, Context context) {
      SharedPreferences prefs = context.getSharedPreferences("KEY_INTEGER", Activity.MODE_PRIVATE);
      return prefs.getInt(key, 0);
   }

   public static void clearIntSession(Context context) {
      Editor editor = context.getSharedPreferences("KEY_INTEGER", Activity.MODE_PRIVATE).edit();
      editor.clear();
      editor.commit();
   }
}

Comments

Popular posts from this blog

SearchView using CursorAdapter

Here  MYFRAGMENT is nothing but name of  a Fragment @Override public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {     inflater.inflate(R.menu.popup, menu);     final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);     final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();     searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));     searchView.setSubmitButtonEnabled(false);     searchView.setIconifiedByDefault(true);     //       searchView.setOnCloseListener(this);     SearchView. OnQueryTextListener textChangeListener = new SearchView. OnQueryTextListener () {         @Override         public boolean onQueryTextSubmit(String query) {             cartAdapt...

Fragment

To enable/disable menu items in Different fragments in same Activity: @Override public void onCreate(@Nullable Bundle savedInstanceState)  {     super.onCreate(savedInstanceState);     setHasOptionsMenu(true);  } @Override public void onPrepareOptionsMenu(Menu menu) {     //Disable the SearchView which is enabled in Product Chart     menu.findItem(R.id.action_search).setVisible(false);   // true to enable } ====================================================

To make a ListView to be scrolled inside of ScrollView

To make a ListView to be scrolled inside of ScrollView: lv . setOnTouchListener ( new ListView . OnTouchListener () { @Override public boolean onTouch ( View v , MotionEvent event ) { int action = event . getAction (); switch ( action ) { case MotionEvent . ACTION_DOWN : // Disallow ScrollView to intercept touch events. v . getParent (). requestDisallowInterceptTouchEvent ( true ); break ; case MotionEvent . ACTION_UP : // Allow ScrollView to intercept touch events. v . getParent (). requestDisallowInterceptTouchEvent ( false ); break ; } // Handle ListView touch events. v . onTouchEvent ( event ); return true ; } }); Refer: http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android