title: Put data in String[] dynamically
body: <p>I want to populate a <code>ListView</code> which reads items from <code>NAMES[]</code>.</p>
  
  <p>The <code>ListView</code> is populated in a <code>Dialog</code>.</p>
  
  <p>I tried using predefined data and it works fine. But not when I put the data in a loop.</p>
  
  <pre><code>public String[] NAMES;
  
  public void forDialog() {
      Dialog dialog = new Dialog(Gorups.this);
      NAMES = new String[]{};
      int j = 1;
      int i = Integer.parseInt(readFile(last));
  
      // Start reading from 1 to "how many files are saved"
      while (j &lt;= i) {
          try {
              FileInputStream fis = openFileInput("filepg" + j + ".txt");
              String a = readFile("filepg" + j + ".txt");
              NAMES[j-1] = a;
              // Here, I want to keep adding data in NAMES by reading all saved files
  
              int size = fis.available();
              byte[] buffer = new byte[size];
              fis.read(buffer);
              fis.close();
          } catch (Exception e) {
              // If limit is reached, break the loop
              break;
          }
          j++;
      }
      dialog.setTitle("Saved Contacts in PG:");
      dialog.setContentView(R.layout.custome_dialog);
      pglist = (ListView)dialog.findViewById(R.id.lvpg);
  
      // Here, I am populating the ListView
      ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;String&gt;(
              Gorups.this,
              android.R.layout.simple_list_item_1, NAMES );
      pglist.setAdapter(arrayAdapter);
      dialog.show();
  }
  </code></pre>
  
  <p>When I run it, <code>ListView</code> is <code>Empty</code>. How do I put values in <code>ListView</code> in a loop?</p>