动态数据添加到ListView控件中的android

编程入门 行业动态 更新时间:2024-10-22 07:21:29
本文介绍了动态数据添加到ListView控件中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ListView其中已经包含数据的列表。

我想要实现的是,当我点击列表项之一,我想补充另一个一堆数据集的正下方点击的项目。

保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){     如果(位置== 0){         / *          *          *要添加另一组数据略低于现在的位置是0!          *         * /     } }

解决方案

您可以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

本文发布于:2023-11-06 13:44:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   动态   数据   ListView   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!