动态数据添加到ListView控件中的android [英] Dynamically add data to ListView in android
问题描述
我有一个ListView其中已经包含数据的列表。
我想要实现的是,当我点击列表项之一,我想补充另一个一堆数据集的正下方点击的项目。
保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
如果(位置== 0){
/ *
*
*要添加另一组数据略低于现在的位置是0!
*
* /
}
}
您可以<一href="http://developer.android.com/reference/android/widget/ArrayAdapter.html#insert%28T,%20int%29">insert您使用列表视图中使用,然后在适配器的数据调用 notifyDataSetChanged()
适配器上更新列表视图。您应该使用ArrayAdapter(或它的子类)能够动态对象添加到列表视图。
((ArrayAdapter)listView.getAdapter())插入(目标,指标)。
((ArrayAdapter)listView.getAdapter())notifyDataSetChanged()。
I've a listview which already contain a list of data.
What I'm trying to achieve is when I click one of the ListItem, I want to add another bunch of dataset just below the clicked item.
protected void onListItemClick(ListView l, View v, int position, long id) {
if (position == 0) {
/*
*
* want to add another bunch of data just below postion 0!!!
*
*/
}
}
You can insert the data in the adapter that you use with list view and then call the notifyDataSetChanged()
on the adapter to update the list view. You should use an ArrayAdapter (or its subclass) to be able to dynamically add objects to the list view.
((ArrayAdapter)listView.getAdapter()).insert(object, index);
((ArrayAdapter)listView.getAdapter()).notifyDataSetChanged();
这篇关于动态数据添加到ListView控件中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!