Add/Remove Items to Android ListView

你离开我真会死。 提交于 2019-12-11 15:12:22

问题


I am creating a listview as ListView listView = new ListView(context); in my activity and I code MyCustomAdapter that extends BaseAdaptor.setting this custom adapter to my listView.setAdapter(myCustomAdpObj) object that I created as above.Now at run time I want to add/remove elements from this listView.I did't find the method how I can do this?any suggestion?thanks


回答1:


remove/add an element and use this.

((BaseAdapter) listView.getAdapter()).notifyDataSetInvalidated();



回答2:


from your item array just remove or add item and call your adapter's notifyDataSetChanged()



来源:https://stackoverflow.com/questions/7712321/add-remove-items-to-android-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!