Home Save an array to sharedpreferences and show it in listview
Reply: 0

Save an array to sharedpreferences and show it in listview

user1465 Published in August 16, 2018, 6:14 am

I need to save user input to shared preferences and also show it from shared preferences in a listview. How can I do this?

Right now my code adds to listview, but does not save it.

ListView listView;
Button AddWebsiteBtn;
EditText WebsiteName;
String[] ListOfWebsites = new String[]{};
SharedPreferences preferences;
SharedPreferences.Editor editor;

protected void onCreate(Bundle savedInstanceState) {
    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 >

    final ArrayAdapter < String > adapter = new ArrayAdapter< String >
            (AddActivity.this, android.R.layout.simple_list_item_1,


    AddWebsiteBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301709 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO