title: CustomAdapter Overwrites Items in ListView - Android
body: <p>This code works, but every time the button is clicked, it overwrites the items in List View instead of adding the items to the bottom of the list. Tried a lot but nothing has solved that issue.</p>
  
  <pre><code>  public static final class ChatRoom2 extends Activity {
  
      Button addButton;
      ListView listView;
      EditText editText;
      TextView values;
      ImageView userimage;
      ChatRow adapter;
      ChatRow adapter2;
      ChatRow listItems;
      String message;
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Intent intent = getIntent();
          String sText = intent.getExtras().getString("textFromList");
          getActionBar().setTitle(sText);
          setContentView(R.layout.chatlayout2);
  
  
          this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
          final int[] images = {R.drawable.image01, R.drawable.image02, R.drawable.image03};
  
  
  
          final int imageId = (int)(Math.random() * images.length);
          userimage = (ImageView) findViewById(R.id.img);
          addButton = (Button) findViewById(R.id.button2);
  
          editText = (EditText) findViewById(R.id.editText);
          values = (TextView) findViewById(R.id.txt);
  
  
          final RowItems weather_data[] = new RowItems[]
                  {
                          new RowItems(images[imageId],message)
                  };
  
          adapter = new ChatRow(this,
                  R.layout.chatmessage, weather_data);
  
  
          listView = (ListView) findViewById(R.id.listView);
  
  
  
           listView.setAdapter(adapter);
  
  
          addButton.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
  
  
                  message = editText.getText().toString();
                  RowItems item = new RowItems(images[imageId], message);
                  adapter.add(item);
                  adapter.notifyDataSetChanged();
  
                  editText.setText("");
  
                  //minimize keyboard 
                  InputMethodManager imm = (InputMethodManager)getSystemService(Context.
                          INPUT_METHOD_SERVICE);
                  imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
  
              }
          });
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; a, View v, int position,
                                      long id) {
  
  
                  Toast.makeText(ChatRoom2.this, "clicked", Toast.LENGTH_LONG)
                          .show();
  
  
  
  
              }
          });
  
      }
  
  
  }
  </code></pre>
  
  <p>This is updated, and it crashes now. Here is logcat</p>
  
  <pre><code>07-06 18:56:40.953  17949-17949/com.example.jason.testlist E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.UnsupportedOperationException
          at java.util.AbstractList.add(AbstractList.java:404)
          at java.util.AbstractList.add(AbstractList.java:425)
          at android.widget.ArrayAdapter.add(ArrayAdapter.java:179)
          at com.example.jason.testlist.ListViewAndroidExample$ChatRoom2$1.onClick(ListViewAndroidExample.java:213)
          at android.view.View.performClick(View.java:4475)
          at android.view.View$PerformClick.run(View.java:18784)
          at android.os.Handler.handleCallback(Handler.java:730)
          at android.os.Handler.dispatchMessage(Handler.java:92)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:5450)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>