jeudi 10 mars 2016

How to write data to shared Preferences which is fetched from sqlite.

when i am fetching all username and password from SQL it is happening. But when I call getDataSql method to store username and password to shared Preferences so it is overwriting with the last value.For Now I have two username and password so the first username and password is overwriting with the last one.

     public void getDataSql()
    {
        List<UserAdapter>UserDetails=dh.getUserDetails();

           for(UserAdapter ud : UserDetails) {
               String log = "Name : " + ud.getName() + " ,Password: " + ud.getPassword();
               // Writing Contacts to log
               Log.d("Name: ", log);


               settings = getApplicationContext().getSharedPreferences("pref", 0);
               editor = settings.edit();
               editor.putString(USER_NAME_KEY, ud.getName());
               Log.i(TAG, ud.getName());
               editor.putString(USER_PASSWORD_KEY, ud.getPassword());
               Log.i(TAG, ud.getPassword());
               editor.apply();


           }
    }

Aucun commentaire:

Enregistrer un commentaire