title: How can I add items in a listview for Android App?
body: <p>I am quite new in android and being requested to develop an app for android. I am working on Android 2.2. The problem I have encountered is that the name of the client should appear once I click the button 'Add' as in the basic tutorial, but it do not work that way. The name did not show on the listview after clicking the button. </p>
  
  <p>Here the codes:</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener,       
  OnKeyListener  {
  
      ArrayList&lt;String&gt; appointment;
      ArrayAdapter&lt;String&gt; aa;
  
      EditText editText1;
      Button addButton;
      ListView listView1;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          editText1 = (EditText)findViewById(R.id.editText1);
          addButton = (Button)findViewById(R.id.addButton);
          listView1 = (ListView)findViewById(R.id.listView1);
  
          addButton.setOnClickListener(this);
          editText1.setOnKeyListener(this);
  
          appointment = new ArrayList&lt;String&gt;();
          aa = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,  
                  appointment);
          listView1.setAdapter(aa);
  
      }
  
      private void addItems(String item){
  
          if (item.length()&gt;0){
              this.appointment.add(item);
              this.aa.notifyDataSetChanged();
              this.editText1.setText("");
          }
  
      }
  
      public void onClick(View v) {
  
          if(v==this.addButton){
              this.addItems(this.editText1.getText().toString());
          }
  
      }
  
  
  
      public boolean onKey(View v, int keyCode, KeyEvent event) {
  
          if (event.getAction()==KeyEvent.ACTION_DOWN &amp;&amp;   
                  keyCode==KeyEvent.KEYCODE_DPAD_CENTER)
              this.addItems(this. editText1.getText().toString());
  
          return false;
      }
  
  
  } 
  </code></pre>
  
  <p>main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;LinearLayout 
  android:orientation="vertical"
  android:layout_width="fill_parent" android:layout_height="wrap_content"     
  android:weightSum="1"&gt;
  
  &lt;ImageView 
  
  android:id="@+id/phones_icon"
   android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:src="@drawable/user"
  android:layout_margin="20dp"
  /&gt;
  
  &lt;Button
  android:text="Add New Appoinments"
  android:id="@+id/addButton"
  android:layout_gravity="center_horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textStyle="bold"
  android:typeface="sans"
    &gt;&lt;/Button&gt;
  
  &lt;EditText android:id="@+id/editText1" android:layout_height="wrap_content"   
  android:layout_width="match_parent" android:inputType="textPersonName"&gt;
      &lt;requestFocus&gt;&lt;/requestFocus&gt;
  &lt;/EditText&gt;
  
  &lt;ListView android:id="@+id/listView1" android:layout_width="wrap_content"  
  android:layout_height="252dp"&gt;&lt;/ListView&gt;  
  
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Please guide me. Thanks in advance</p>