Android ListView动态添加数据

Android ListView动态添加数据,android,listview,dynamic,Android,Listview,Dynamic,我有一个要动态添加数据的列表视图。 下面是我想要添加数据的XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height=

我有一个要动态添加数据的列表视图。 下面是我想要添加数据的XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView android:id="@+id/rowTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="70dp"
    android:padding="12dp"
    android:textSize="16sp" >
  </TextView>

  <TextView android:id="@+id/alarm_name_text" 
   android:layout_height="wrap_content" 
   android:text="" 
   android:layout_below="@+id/rowTextView" 
   android:layout_width="fill_parent">
   </TextView>

  <CheckBox android:id="@+id/CheckBox01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp"
    android:layout_alignParentRight="true" android:layout_marginRight="6sp"
    android:focusable="false">
  </CheckBox>

</RelativeLayout>

您需要处理呈现各行的代码部分。查看以下位置的教程:特别是如何使用
getView

只需将元素添加到
ArrayList
中,并调用
notifyDataSetChanged()
到数组适配器。

请提供更多信息:适配器的类别是什么?您的数据的容器是什么?我没有必要放置该类,并且我指定使用ArrayList/adapter?我需要有关如何从仅包含文本视图的列表视图中添加/删除数据的帮助。应该是相对简单的,但我有很大的困难,这看起来非常有用,我goona检查它现在谢谢!)但我仍然想知道如何动态地更改用户输入中已有的文本视图?这只是基于当前数据填充视图。您始终可以删除一个项目并将一个新项目插入适配器:这应该可以满足您的需要。你需要调用适配器上的
notifyDataSetChanged
方法来强制它接受更改。哇,谢谢,我的大脑刚刚开始工作。我有个主意:)最后一个问题是关于必须从我的列表中添加或删除项目。我应该将添加或删除它们的函数放在哪里?它们是如何被调用的?您需要确保调用发生在主活动线程上:因此在侦听器回调中,使用处理程序或使用
View.post
。提供了一个很好的概述。非常感谢。我已经有这个问题大约一个星期了,它阻止了我继续前进。我会继续尝试:)有一件事我不明白,为什么我在实现自己的getItem()函数时会出错。我不能将它声明为Object类型,我必须将它声明为我想要的类的类型。与你为我发布的第一个链接不同,
public void addItems(View v)
        {
            rowSavedText.setText(getString());
            planetList.add(new Planet("This one"));
            listAdapter.notifyDataSetChanged();
        }