public void addTask(Task task) { /* Adds a new task to the list view and saves its data in the SharedPreferences file. */ adapter.add(task); keys.add(task.getKey()); SharedPreferences.Editor edit = appData.edit(); edit.putString(task.getKey(), task.getName() + "\n" + task.getDescription()); edit.apply(); }
public ListViewExtended(Activity activity, ListView view, ArrayList<Task> tasks) { /* Creates a new instance of the class with specified parameters. This constructor takes the list of activities and fills the app with them. */ listView = view; keys = new ArrayList<>(tasks.size()); for (Task task : tasks) keys.add(task.getKey()); appData = activity.getPreferences(Context.MODE_PRIVATE); adapter = new ArrayAdapter<>(activity, R.layout.activity_list_view_item, tasks); listView.setAdapter(adapter); }
public void cancelTask(String key) { /* Removes a task from the list view with a given key. Also deletes data about this task from appData. */ for (int i = 0; i < adapter.getCount(); i++) if (adapter.getItem(i).getKey().equals(key)) { Task task = adapter.getItem(i); adapter.remove(task); keys.remove(task.getKey()); SharedPreferences.Editor edit = appData.edit(); edit.remove(key); edit.apply(); } }