// Set the text in each new row.
((TextView) newViews[i].findViewById(android.R.id.text1)).setText(selectedItems[i]);

// Because mContainerView has android:animateLayoutChanges set to true,
// adding this view is automatically animated.

mContainerView.addView(newViews[i], 0);

// Set a click listener for the "X" button in the row that will remove the row.
OnClickListener listener = new MyAddItemListener(newViews[i], mContainerView, this);
newViews[i].findViewById(R.id.delete_button).setOnClickListener(listener);