Skip to content

[HashMap: key -> value ] to ListView  #2

@Thelin90

Description

@Thelin90

` /**
* Will get the data from the map data structure, not the best solution, but it will work
* for now. Would rather have implemented a better solution where the map where better integrated
* with the ArrayAdapter, but not that much time.
*/
public void fetchNotes() {

        adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.support_simple_spinner_dropdown_item, getArrayList());
        listview.setAdapter(adapter);

        Map<String, Object> map = getMap("map", ShowNotes.this);

        if(map != null) {
            Iterator myVeryOwnIterator = map.keySet().iterator();
            while (myVeryOwnIterator.hasNext()) {
                String key = (String) myVeryOwnIterator.next();
                String value = (String) map.get(key);
                push(value + "\n" + key);
            }
            adapter.notifyDataSetChanged();
        } else {
            Toast.makeText(getApplicationContext(), "There is no notes to print, maybe you should make some notes first!", Toast.LENGTH_LONG).show();
        }
    }`

There must be a more nice way to add data from a hashmap to a listview without having to use an ArrayList, how to do this properly?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions