我需要将用户输入保存到共享首选项,并从列表视图中的共享首选项中显示它。我怎样才能做到这一点?
现在我的代码添加到列表视图,但不保存它。
ListView listView;
Button AddWebsiteBtn;
EditText WebsiteName;
String[] ListOfWebsites = new String[]{};
SharedPreferences preferences;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
listView = (ListView) findViewById(R.id.list_of_websites);
AddWebsiteBtn = (Button) findViewById(R.id.btn_submit);
WebsiteName = (EditText) findViewById(R.id.website_name);
//using this part to add it to listview, maybe will need to remove it when shared preferences will work
final List< String > ListElementsArrayList = new ArrayList< String >
(Arrays.asList(ListOfWebsites));
final ArrayAdapter < String > adapter = new ArrayAdapter< String >
(AddActivity.this, android.R.layout.simple_list_item_1, …Run Code Online (Sandbox Code Playgroud)