Android的ListView中动态添加数据 [英] Android ListView dynamically adding data
问题描述
我有我想要动态数据添加到ListView。
这里就是我想要将数据添加到XML。
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT> < TextView的机器人:ID =@ + ID / rowTextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =70dp
机器人:填充=12dp
机器人:TEXTSIZE =16SP>
< / TextView的> < TextView的机器人:ID =@ + ID / alarm_name_text
机器人:layout_height =WRAP_CONTENT
机器人:文字=
机器人:layout_below =@ + ID / rowTextView
机器人:layout_width =FILL_PARENT>
< / TextView的> <复选框机器人:ID =@ + ID / CheckBox01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=10dp
机器人:layout_alignParentRight =真正的机器人:layout_marginRight =6SP
机器人:可聚焦=假>
< /复选框>< / RelativeLayout的>
我要用户输入在EDITTEXT dialogView一些数据后,将数据添加到与ID alarm_name_text第二TextView的。有人告诉我,做一个功能,增加了数据的ArrayList的我/适配器,但我不知道什么时候调用它或它如何被使用。我需要帮助PLZ :(。这里的功能。
公共无效为addItems(视图V)
{
rowSavedText.setText(的getString());
planetList.add(新星球(这一项));
listAdapter.notifyDataSetChanged();
}
您需要在code呈现各行的一部分工作。看看教程在<一个href=\"http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx\" rel=\"nofollow\">http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx:特别是它如何使用 getView
。
I have a listView that I want to dynamically add data to. here's the XML I want to add the data to.
<?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>
I want to add data to the 2nd TextView with the id alarm_name_text after a user has entered some data in an editText dialogView. I've been told to make a function that adds the data the my ArrayList/adapter but I'm not sure when to call it or how it's being used.. I needs help plz :(. Here's the function.
public void addItems(View v)
{
rowSavedText.setText(getString());
planetList.add(new Planet("This one"));
listAdapter.notifyDataSetChanged();
}
You'll need to work on the part of the code that renders the individual rows. Take a look at the tutorial at http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx: specifically how it uses getView
.
这篇关于Android的ListView中动态添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!