Android -- Adding and removing items from a multiline ListView with a custom ArrayAdapter
<p>I am trying to construct a multiline ListView backed by an ArrayAdapter. I would like each row in the list to have two lines and a delete button next to it. When the delete button is clicked, the items in the arrays should be removed and the ListView should refresh itself.</p>

<p>This is the code for the MainActivity, which has an inner class that is the custom ArrayAdapter:</p>

<pre><code>public class MainActivity extends Activity {
ArrayList&lt;String&gt; artistsList = new ArrayList&lt;String&gt;();
String[] artists = {"Matt Nathanson", "Green Day", "Three Days Grace", "LMFAO", "One Direction", 
        "Linkin Park", "Neon Trees", "Cee Lo Green", "Plain White T's", "Metallica", "Maroon 5",
        "Sick Puppies", "Bruno Mars", "Billy Joel", "Don McLean", "Adele", "Gary Jules"};
ArrayList&lt;String&gt; songsList = new ArrayList&lt;String&gt;();
String[] songs = {"Come On Get Higher", "Holiday", "I Hate Everything About You", "Sexy and I Know It", "What Makes You Beautiful",
        "What I've Done", "Animal", "Fuck You", "Hey There Delilah", "Sandman", "Moves Like Jagger",
        "Rip Tide", "Talking to the Moon", "Piano Man", "American Pie", "Someone Like You", "Mad World"};

ListView list;
TestArrayAdapter mArrayAdapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    for(String s : artists) {
        artistsList.add(s);
    }
    for(String s : songs) {
        songsList.add(s);
    }

    mArrayAdapter = new TestArrayAdapter();

    list = (ListView)findViewById(R.id.mainlist);

    list.setAdapter(mArrayAdapter);
}


class TestArrayAdapter extends ArrayAdapter&lt;String&gt; {

    public TestArrayAdapter() {
        super(MainActivity.this, R.layout.row, songs);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row=inflater.inflate(R.layout.row, parent, false);

        TextView primaryTextView = (TextView)row.findViewById(R.id.primaryTextView);
        TextView secondaryTextView = (TextView)row.findViewById(R.id.secondaryTextView);

        primaryTextView.setText(songsList.get(position));
        secondaryTextView.setText(artistsList.get(position));

        ImageView deleteButton = (ImageView)row.findViewById(R.id.deleteRowButton);
        deleteButton.setTag(position);
        deleteButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                artistsList.remove(v.getTag());
                songsList.remove(v.getTag());
                mArrayAdapter.notifyDataSetChanged();
            }
        });

        return row;
    }
}
</code></pre>

<p>Calling notifyDataSetChanged() does not seem to do anything; however, the items in the ArrayLists are being deleted. The ListView seems to be independent of changes that I make in the ArrayLists and the ArrayAdapter. Ideally, when I remove an item from the underlying data, I should be able to call notifyDataSetChanged() and the ListView will update itself.</p>

<p>I have looked at the other questions similar to this, but all of them have only a single ArrayList providing data to the ListView, and I can't figure out how to adapt those solutions for multiline rows. Thanks in advance.</p>
