Android: notifyDataSetChanged(); not working

后端 未结 8 1553
旧时难觅i
旧时难觅i 2020-11-28 10:33

I have a database in a server and from a Tablet I take some values from one table in the database. I load this information correctly into a list but I would like to know why

8条回答
  •  Happy的楠姐
    2020-11-28 11:18

    An adapter define the comportement of the layout ! -> setListAdapter() : Define the adapter for a ListView/GridView/Gallery... but you need to specify the data !

    I recommend to you, to initialize 'setListAdapter' in the 'onCreate' or in the constructor. After you set the data into the adapter (exemple : adapter.setItem(yourData))

    And NOW ! You should to call notifyDataSetChanged ! Because you have changed the data but the view isn't refresh and notifydatasetchanged() reload the content of the view (ListView/GridView/Gallery...)

    For a good practice and understand correctly I recommend to you to use a 'custom adapter' using 'baseAdapter'

    Read and do this tutorial (I haver learn with this): http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

    Read the documentation : http://developer.android.com/reference/android/widget/BaseAdapter.html

提交回复
热议问题