0

I'm not sure if i made good title (still new in android).

Question: If I make function:

    public void refresh_lists() {
    // wyswietlanie listy miesiecy
    ArrayAdapter<String> month_adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, miesiac_data);
    month_list_v.setAdapter(month_adapter);

    // wyswietlanie listy dni
    ArrayAdapter<String> daily_adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, dzien_data);
    daily_list_v.setAdapter(daily_adapter);
}

(miesiac_data and dzien_data are String arrays) Then remake arrays somewhere else, like:

miesiac_data[] = new String[new_length];
dzien_data[] = new String[new_length];

Then add new records to arrays and finally, add refresh_list function as onClick() effect, does it create new lists everytime I push button, or just refreshes old ones?

biegleux
  • 13,179
  • 11
  • 45
  • 52
user1709804
  • 35
  • 1
  • 3
  • What you mean "create new lists" or "refresh old ones". Are you talking about the String arrays? – Simon Sep 30 '12 at 13:23
  • um, hard to explain (i lack words lol..): With lists i mean ArrayAdapters, which show simple lists on device (simple list = http://windrealm.org/tutorials/android/simple-android-listview.png). not sure if i made it clearer now :| – user1709804 Sep 30 '12 at 13:28
  • Then use daily_adapter.notifyDataSetChanged(). This tells the adapter that the underlying data (your String[]) has changed. The adapter will refresh itself and in turn, the ListView which is bound to it. – Simon Sep 30 '12 at 13:31
  • not sure if i used it as it should be. I call daily_adapter.notifyDataSetChanged() after recreation of arrays with new entries, so it should display new content, but it shows only old one. (Tho, new content is in array for sure, i checked it via log..) – user1709804 Sep 30 '12 at 15:46
  • Ah, sorry.I see now. notifyDataSetChanged only works if you use the add,delete etc methods of the ArrayAdapter. use daily_adapter = new ArrayAdapter again or change your code to use the ArrayAdapter data modification methods. – Simon Sep 30 '12 at 15:52
  • See this http://stackoverflow.com/questions/3669325/notifydatasetchanged-example/5092426#5092426 – Simon Sep 30 '12 at 15:53

0 Answers0