title: To Do List Android app crashes after search
body: <p>The problem that I am having is that once I perform a search on my ListView, I am unable to delete or add anything else to my List. Additionally, I am getting an IndexOutofBounds error. My code is as follows:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  public ArrayList&lt;String&gt; array;
  public ArrayAdapter&lt;String&gt; adapt;
  public ListView list;
  public EditText search;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      list = (ListView) findViewById(R.id.list_item);
      array = new ArrayList&lt;&gt;();
      adapt = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, array);
      list.setAdapter(adapt);
      setupListViewListener();
      search();
  }
  
  public void onAddItem(View v) {
      EditText edit = (EditText) findViewById(R.id.edit);
      String item = edit.getText().toString();
      adapt.add(item);
      edit.setText("");
  }
  
  public void setupListViewListener() {
      list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View v, int i, long l) {
              array.remove(i);
              adapt.notifyDataSetChanged();
              return true;
          }
      });
  }
  
  public void search()
  {
      search = (EditText) findViewById(R.id.inputSearch);
      search.addTextChangedListener(new TextWatcher() {
  
          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
              adapt.getFilter().filter(cs);
              adapt.notifyDataSetChanged();
          }
  
          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
          }
  
          @Override
          public void afterTextChanged(Editable arg0) {
          }
      });
  }
  
  public void deleteAll(View view) {
      adapt.clear();
      adapt.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>}</p>