android中动态添加数据到ListView [英] Dynamically add data to ListView in android

查看:20
本文介绍了android中动态添加数据到ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经包含数据列表的列表视图.

I've a listview which already contain a list of data.

我想要实现的是,当我单击 ListItem 中的一个时,我想在单击的项目下方添加另一组数据集.

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!!!
         * 
        */
    }
}

推荐答案

您可以插入您与列表视图一起使用的适配器中的数据,然后调用适配器上的 notifyDataSetChanged() 以更新列表视图.您应该使用 ArrayAdapter(或其子类)才能将对象动态添加到列表视图中.

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();

这篇关于android中动态添加数据到ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆