Reputation: 53
Hello I have a program which creates a random string every 3 seconds After generating string I want to save it and show all strings in a listview Thanks for any help
Upvotes: 0
Views: 55
Reputation: 32221
You got planty of storage options when working with Android.
Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.
Your data storage options are the following:
Shared Preferences Store private primitive data in key-value pairs. Internal Storage Store private data on the device memory. External Storage Store public data on the shared external storage. SQLite Databases Store structured data in a private database. Network Connection Store data on the web with your own network server.
Read more about it here.
Upvotes: 0
Reputation: 56
create ArrayList
ArrayList<String> itemList = new ArrayList<>(Arrays.asList(subject));
then Add the String to ArrayList
itemList.add("your String");
use the below code to show them as list
adapter = new ArrayAdapter<>(this, simple_list_item_1, itemList);
ListView listV = (ListView) findViewById(R.id.list1);
listV.setAdapter(adapter);
Upvotes: 0
Reputation: 320
If you want to save it permanently you should read about SQLiteDatabases in Android.
If it can be deleted after you app closes you can just store it in a member variable. See here for some hints: How to fill a ListView with a string-array?
Upvotes: 1