0

I have to list all the elements of a String Array in a two line listView.

The String Array is dynamically and can either change in size or in content. So when the size of the String Array is 5 for example 5 listView elements shall be shown.

Have you got any idea how to do that?

I have tried it with this, but this list only the first element:

 // wenn noch keine Standorte hinterlegt sind gibt es eine CursorIndexOutOfBoundsException
    try {
        datum_global = datenBankHelper.get_datum();
        int alle_eintraege_aller_datumsangaben = datum_global.length; // Alle Einträge von allen Datumsangaben (auch von gleichen)

        Log.d("size", "size " + alle_eintraege_aller_datumsangaben + "|" + datum_global[0]);        // z.B. 27, da 27 Einträge für alle Datumsangaben

        for(int i= 0; i < alle_eintraege_aller_datumsangaben; i++) {
            gespeicherte_routen = new String[][]{
                    {datum_global[i], "Anzahl Einträge: " + "Test"}
            };
        }

    } catch (CursorIndexOutOfBoundsException cs){

    }


    @SuppressWarnings("Convert2Diamond") ArrayList<HashMap<String, String>> list = null;

    // wenn noch keine Standorte hinterlegt sind gibt es eine NullPointerException
    try {
        list = new ArrayList<HashMap<String, String>>();


        HashMap<String, String> item;
        for (String[] routen : gespeicherte_routen) {

            Log.d("schleife3", "schleife3 " + routen[0] + "|" + routen[1] + gespeicherte_routen.length);
            //noinspection Convert2Diamond
            item = new HashMap<String, String>();
            item.put("line1", routen[0]);
            item.put("line2", routen[1]);

            list.add(item);
        }

    }catch(NullPointerException np){

    }

Thanks for helping.

2
  • can you explain it more clearly Commented Aug 31, 2016 at 12:02
  • 1
    It is the simple listview, nothing special. Use any listView tutorial, found in google in about 8 seconds Commented Aug 31, 2016 at 12:03

1 Answer 1

1

a ListView needs an Adapter to show the data, and the Adapter needs a List (of strings in this case). if you change the values in the list you just need to call notifyDataSetChanged() on the Adapter and the ListView will update on its own

ListView mListView;
ArrayAdapter mAdapter;
List<String> mList;

//...

mAdapter = new ArrayAdapter(context, R.layout.something, mList);
mListView.setAdapter(adapter);

// .. 

mList.add("bla bla");
mAdapter.notifyDataSetChanged();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.