Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using a Hasmap instead of ArrayList. </p> <pre><code> public class MainActivity extends Activity { ArrayList&lt;Contact&gt; imageArry = new ArrayList&lt;Contact&gt;(); ContactImageAdapter adapter; File folder; int j = 0; Hashmap&lt;String,String&gt; FilesInFolder; //Filename:ModificationDate pairs @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); folder = new File(Environment.getExternalStorageDirectory() + "/tc/"); FilesInFolder = GetFilesData(folder.getAbsolutePath()); for (Map.Entry&lt;String, String&gt; current_file:FilesInFolder.entrySet()) { // imageArry.add(new Contact(R.drawable.ic_launcher, current_file.getKey(), current_file.getValue())); } adapter = new ContactImageAdapter(this, R.layout.list, imageArry); ListView dataList = (ListView) findViewById(R.id.list); dataList.setAdapter(adapter); } public HashMap&lt;String,String&gt; GetFilesData(String DirectoryPath) { HashMap&lt;String,String&gt; MyFiles = new HashMap&lt;String,String&gt;(); File f = new File(DirectoryPath); File[] files = f.listFiles(); if (files.length == 0) return null; else { for (int i=0; i&lt;files.length; i++) { if (files[i].getName().endsWith(".tol")) { long lastTime = files[i].lastModified(); String fileName = files[i].getName().substring(0, files[i].getName().lastIndexOf(".")); String dateString = DateFormat.format("MM/dd/yyyy", new Date(lastTime)).toString(); MyFiles.put(fileName,dateString); //Add the new filename and its modification date to the Hasmap } } } return MyFiles; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>Code not tested. Minor changes may be required. You will need to import HashMap &amp; Map classes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload