Android-以编程方式将项目添加到列表视图 [英] Android - add items to list view programmatically
本文介绍了Android-以编程方式将项目添加到列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在android中创建一个待办事项列表,其中每个项目都是一个复选框.我希望能够以编程方式更新用户(我)添加新任务时的项目列表.有关如何实现此目标的任何提示?
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?
推荐答案
As suggested notepad tutorial would be good here is a few design tips:
- 您可能需要使用listview创建布局
- 然后为列表行创建另一个布局以使其中的内容膨胀 您的案例复选框
- 为列表视图创建适配器,以通过扩展ArrayAdapter来设置项目.
- 实现getView方法和适配器类的构造函数
- 如果用户向列表中添加一些内容,则通知适配器数据集具有 相应地更改并更新了用户界面
- You probably need to create layout with listview
- Then create another layout for your list rows to inflate which is in your case checkbox
- Create adapter for listview to set items by extending ArrayAdapter.
- Implement getView method and constructor of adapter class
- 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
注2:在列表中,android具有行回收功能,因此当列表扩展屏幕宽度时,请检查复选框是否保持其状态.
Note 2 : In lists android have row recycle so when list expend the screen width check if checkboxes hold their states.
希望有帮助.
这篇关于Android-以编程方式将项目添加到列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文