2016-08-09 37 views
0

在我的应用程序中有两个edittext和一个按钮。一个是id,另一个是出生日期。用户可以将ID & dob然后单击添加按钮。在重新启动应用程序后显示listview项目

此ID和出生日期必须存在于数据库中。如果用户点击添加按钮,用户的ID和名称将显示在列表视图中。

在这里,我可以轻松地检索json数据并将其显示在列表视图中,但是当我关闭应用程序并重新启动应用程序时,那些添加的项目将被删除。

我该如何解决这个问题?假设在Facebook中,如果我们将朋友添加到我们的朋友列表中,那么在关闭应用后它永远不会被删除。这里是我的代码链接:

code here: https://ideone.com/LM4HzE 

回答

1
1.Better to store the Data in SQlite Or Shared preference 
Retreived data should be stored in Shared preference or Sqlite the data will not be Erased otherwise the data will be erased, 


    Store: 
     SharedPreferences app_preferencesnew = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 
      SharedPreferences.Editor editor = app_preferencesnew.edit(); 
      editor.putBoolean("bfirsttime", true); 
      editor.putString("selected", selected); 
      editor.commit(); 

    Retreive: 
     String userId = app_preferencesnew.getString("selected", ""); 
+0

我已经尝试过共享首选项,但无法理解如何解决。这里是我的代码:https://ideone.com/LM4HzE – tanzilamohita

+0

把键值应该是相同的,你把id名称值 – YUVRAJ

+0

studentID.setText(prefs.getString(“autoSave1”,“”)); DOB.setText(prefs.getString(“autoSave2”,“”)); editor.putString(autoSave1,id); editor.putString(autoSave2,dob); – YUVRAJ

相关问题