package com.codepath.simpletodo;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

import java.util.ArrayList;


public class MainActivity extends ActionBarActivity {
    ArrayList<String> items;
    ArrayAdapter<String> itemsAdapter;
    ListView lvItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lvItems = (ListView) findViewById(R.id.lvItems);
        items = new ArrayList<String>();
        itemsAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, items);

        lvItems.setAdapter(itemsAdapter);
        items.add("First Item");
        items.add("Second Item");
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void onAddItem(View v) {
        EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
        String itemText = etNewItem.getText().toString();

        itemsAdapter.add(itemText);
        etNewItem.setText("");
    }
}

@@ -184,16 +184,51 @@
 w.View;%0A
+import android.widget.AdapterView;%0A
 import a
@@ -255,16 +255,16 @@
 dapter;%0A
-
 import a
@@ -977,24 +977,58 @@
 cond Item%22);
+%0A%0A        setupListViewListener();
 %0A    %7D%0A%0A%0A   
@@ -1985,16 +1985,481 @@
 xt(%22%22);%0A
-
     %7D
+%0A%0A    private void setupListViewListener() %7B%0A        lvItems.setOnItemLongClickListener(%0A            new AdapterView.OnItemLongClickListener() %7B%0A                @Override%0A                public boolean onItemLongClick(AdapterView%3C?%3E adapter,%0A                        View view, int pos, long id) %7B%0A                    items.remove(pos);%0A                    itemsAdapter.notifyDataSetChanged();%0A                    return true;%0A                %7D%0A        %7D);%0A    %7D%0A%0A%0A%0A
 %0A%7D%0A

Remove items from the list using the LongClickListener