title: Search and Adding Item in Dynamic ListView
body: <p>I am trying to dynamically add name of movies  in listview and after that i want to use search option to find the movie name if movie name is not found in a listview add the movie in listview.My problem is Before using search, movie name inserted in a listview properly After using search, movie name not inserted in listview. </p>
  
  <pre><code>public class MainActivity extends ListActivity implements OnClickListener {
  
          ArrayList&lt;String&gt; listItems=new ArrayList&lt;String&gt;();
  
  
          ArrayAdapter&lt;String&gt; adapter;
          EditText et,inputSearch;
  
  
          Button btn;
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
              adapter=new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,listItems);
              setListAdapter(adapter);
              adapter.notifyDataSetChanged();
  
              et=(EditText) findViewById(R.id.editText);
              final EditText inputSearch = (EditText) findViewById(R.id.inputSearch);
              btn=(Button) findViewById(R.id.addBtn);
              btn.setOnClickListener(this);
  
  
              inputSearch.addTextChangedListener(new TextWatcher() {
  
                  @Override
                  public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
  
                      MainActivity.this.adapter.getFilter().filter(cs);  
                      adapter.notifyDataSetChanged();
  
  
  
                  }
  
                  @Override
                  public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                          int arg3) {
                      // TODO Auto-generated method stub
  
                  }
  
                  @Override
                  public void afterTextChanged(Editable arg0) {
                      // TODO Auto-generated method stub                          
                  }
              });
              }
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              if (isInputValid(et)) {
                  listItems.add(0,et.getText().toString());
                  et.setText("");
  
                  adapter.notifyDataSetChanged();
  
  
          }
  
  
  
  
      }
  
               protected boolean isInputValid(EditText etInput2) {
                      // TODO Auto-generatd method stub
                      if (etInput2.getText().toString().trim().length()&lt;1) {
                          etInput2.setError("Please Enter Item");
                          return false;
                      } else {
                          return true;
                      }
  
  
  
      }
      }
  </code></pre>