title: Is there any way of tracking an item in a list view when it changes positions?
body: <p>The following code works well:</p>
  <pre><code>    listView = findViewById(R.id.my_list);
  
      String[] values = new String[]{
              &quot;TRT 1&quot;, &quot;TRT Haber&quot;
      };
      listView.setAdapter(arrayAdapter);
  
      values = new ArrayList&lt;&gt;(Arrays.asList(values)).toArray(new String[0]);
      arrayAdapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1,values);
      listView.setAdapter(arrayAdapter);
  
      listView.setOnItemClickListener((parent, view, position, id) -&gt; {
          if (position == 0) {
              Intent intent = new Intent(view.getContext(), Activity1.class);
              startActivity(intent);
          }
          if (position == 1) {
              Intent intent = new Intent(view.getContext(), Activity2.class);
              startActivity(intent);
          }
      });
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main2, menu);
      MenuItem menuItem = menu.findItem(R.id.search2);
      SearchView searchView = (SearchView) menuItem.getActionView();
      searchView.setQueryHint(&quot;Search channels&quot;);
  
      searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String s) {
              return false;
          }
  
          @Override
          public boolean onQueryTextChange(String s) {
              SearchActivity.this.arrayAdapter.getFilter().filter(s);
              return true;
          }
      });
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  <p>When I search for an item in the list view it becomes the first item in the list (Which I want to happen) but if the second item in the list changes positions it opens the wrong activity. I know this is because of the if statement and position as follows, but I’ve been stuck on how to fix it for about a day now...</p>
  <pre><code>    listView.setOnItemClickListener((parent, view, position, id) -&gt; {
          if (position == 0) {
              Intent intent = new Intent(view.getContext(), Activity1.class);
              startActivity(intent);
          }
          if (position == 1) {
              Intent intent = new Intent(view.getContext(), Activity2.class);
              startActivity(intent);
          }
      });
  }
  </code></pre>
  <p>Any help is much appreciated. *No errors are shown</p>