Android - add items to list view programmatically

北慕城南 提交于 2019-12-23 21:08:42

问题


I'm trying to create a to do list in android, where each item is a checkbox. I want to be able to programmatically update the list of items as the user (me) adds a new task. Any tips for how I could accomplish this?


回答1:


As suggested notepad tutorial would be good here is a few design tips:

  1. You probably need to create layout with listview
  2. Then create another layout for your list rows to inflate which is in your case checkbox
  3. Create adapter for listview to set items by extending ArrayAdapter.
  4. Implement getView method and constructor of adapter class
  5. If user add something to list notify adapter that data set has changed and update ui accordingly

Note : do not update UI from background thread just use UI thread for this

Note 2 : In lists android have row recycle so when list expend the screen width check if checkboxes hold their states.

Hope it helps.



来源:https://stackoverflow.com/questions/7053985/android-add-items-to-list-view-programmatically

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