title: How can i combine search listview and ListView.OnItemClickListener
body: <p>I have a <code>search listview</code>, and i'm trying to combine the search <code>listview</code> with <code>onItemClickListener</code> using switch case like this. So that a user  can search an item and click it to do another activity.</p>
  <p><strong>Here is sample screen shot</strong></p>
  <p><a href="https://i.stack.imgur.com/D0lDL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D0lDL.png" alt="enter image description here" /></a></p>
  <p><strong>Here is my code</strong></p>
  <pre><code>    public class MainActivity extends AppCompatActivity {
  
      String[] items;
      ArrayAdapter&lt;String&gt; adapter;
      ArrayList&lt;String&gt; listItems;
      ListView listView;
      EditText editText;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          editText = findViewById(R.id.txtSearch);
          listView = findViewById(R.id.listName);
          initList();
          editText.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                  if(charSequence.toString().equals(&quot;&quot;)){
                      initList();
                  }else{
                      searchItem(charSequence.toString());
                  }
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
  
              }
          });
  
          listView.setOnItemClickListener(listener);
  
  
  
  
      }
  
  
      ListView.OnItemClickListener listener = new ListView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              switch (listView.getSelectedItemPosition()){
                  case 0:
                      changeActivity();
                      break;
  
                  case 1:
                      changeActivity();
                      break;
  
                  case 2:
                      changeActivity();
                      break;
                  case 3:
                      changeActivity();
                      break;
              }
  
          }
      };
  
      public void changeActivity(){
          Intent intent = new Intent(MainActivity.this, Main2Activity.class);
          intent.putExtra(&quot;Key&quot;, &quot;Value&quot;);
          startActivity(intent);
      }
  
  
  
      public void searchItem(String textSeache){
          for (String item:items){
              if(!item.contains(textSeache)){
                  listItems.remove(item);
              }
          }
          adapter.notifyDataSetChanged();
      }
  
      public void initList(){
          items = new String[]{&quot;California, USA&quot;, &quot;Toronto,  CANADA&quot;, &quot;Beijing,  CHINA&quot;, &quot;Taipei,   TAIWAN&quot;};
          listItems = new ArrayList&lt;&gt;(Arrays.asList(items));
          adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.list_item, R.id.txtItem, listItems);
          listView.setAdapter(adapter);
      }
  
  
  }
  </code></pre>
  <p>Can anyone please help me?</p>