title: Android search through an string-array and get results into a ListView
body: <p>I want to search into a string-array and get the result into a ListView.</p>
  
  <p>So, if I have</p>
  
  <pre><code>&lt;string-array name="Colors"&gt;
      &lt;item&gt;Red&lt;/item&gt;
      &lt;item&gt;Yellow&lt;/item&gt;
      &lt;item&gt;Blue&lt;/item&gt;
      &lt;item&gt;DarkRed&lt;/item&gt;
  &lt;/string&gt;
  </code></pre>
  
  <p>and I search for "Red", I should get into the ListView two items. For each item I would like to know the ID into the string array and the string value, which would be displayed in the ListView.</p>
  
  <p>While searching for results I would like to display a ProgressBar (indeterminate status) that disappears when all is finished.</p>
  
  <p>A first step would be getting the string-array into a List or String[], then create a new Thread that compares each item of the array and put on the ListView those matching the search text.</p>
  
  <p>I don't know which is the best way of doing it. My code is something like this:</p>
  
  <pre><code>public class SearchActivity extends Activity {
      private ProgressBar mProgress;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.search);
  
          mProgress = (ProgressBar) findViewById(R.id.Progress);
  
          new Thread(new Runnable() {
              public void run() {
              int item_pos = 0;
              int item_count = 0;
  
              String[] Colors = getResources().getStringArray(R.array.Colors); 
                  item_count = Colors.length();
  
                  mProgress.setVisibility(View.VISIBLE);
  
                  while (item_pos &lt; item_count) {
                      // Compare with the search text
                      // Add it to the ListView (I don't know how)
                      item_pos +=1;
                  }
                  mProgress.setVisibility(View.GONE);
              }
          }).start();
      }
  }
  </code></pre>
  
  <p>So, my questions:</p>
  
  <ol>
  <li>How do I get both item id and string then compare each text value with the search text?</li>
  <li>How do I add an item to the ListView?</li>
  <li><p>Why the ProgressBar is not visible? The ProgressBar XML code is this:</p>
  
  <pre><code>&lt;ProgressBar
      android:id="@+id/Progress"
      style="@android:style/Widget.ProgressBar.Small"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:indeterminate="true"
      android:visibility="visible" /&gt;
  </code></pre></li>
  </ol>
  
  <p>Thanks for all of your suggestions and help!</p>