cj1098
cj1098

Reputation: 1600

Android ListView dynamically adding data

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

Upvotes: 0

Views: 4735

Answers (2)

Ognyan
Ognyan

Reputation: 13600

Just add the element to your ArrayList and call notifyDataSetChanged() to your array adapter.

Upvotes: 0

Femi
Femi

Reputation: 64700

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.

Upvotes: 1

Related Questions