Yanshof
Yanshof

Reputation: 9926

How to present dynamic string collection on android application

In my application - i need to present ( in the UI ) some dynamic string collection.

This collection need to have ability to add/remove some string that comes from other component.

The string collection exist on some singleton class.

What is the easy way to show this dynamic collection ?

Thanks

Upvotes: 0

Views: 88

Answers (2)

Maurizio Ricci
Maurizio Ricci

Reputation: 472

You can declare your string in a linked list, then you create a listview. You create a base adapter witch takes as arguments your string list and pass the adapter to the list view;

ArrayAdapter<String> adapter = new ArrayAdapter <>(this, android.R.layout.simple_list_item_1, yourStringValues)
listView.setAdapter(adapter)

your string items will be showed to the user, then you may want to implement listview's on touch listener in order to show a menu which can be used to delete an element

Upvotes: 1

Rajesh N
Rajesh N

Reputation: 6693

  1. Store Dynamic collection in Shared preference in json format using GSON libray.
  2. Retrive and parse usong GSON libray to display it anywhere
  3. Implement Interface or local bradcast where ever is added/updated/removed and updated value and restore it in shared preference

Upvotes: 1

Related Questions