Android: notifyDataSetChanged(); not working

后端 未结 8 1515
旧时难觅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条回答
  • 2020-11-28 11:14

    If everything you set fine and still not working then your list... Is it Mutablekind of the List or not...!

    private val demoList: MutableList<AnyClass> = mutableListOf()
    

    once you define your list like above mutable manner then you can get the method

    .add
    .addAll
    .remove
    

    etc...

    else if you have created normal list then that will not work as notifyDataSetChanged

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题