Note that there are some explanatory texts on larger screens.

plurals
  1. POGet filename and file modified date to use for listview
    primarykey
    data
    text
    <p>I have the following code:</p> <pre><code>package com.example.customlistview; import java.io.File; import java.util.ArrayList; import java.util.Date; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.text.format.DateFormat; import android.view.Menu; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends Activity { ArrayList&lt;Contact&gt; imageArry = new ArrayList&lt;Contact&gt;(); ContactImageAdapter adapter; File folder; int j = 0; ArrayList&lt;String&gt; FilesInFolder, FileLastModified; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); folder = new File(Environment.getExternalStorageDirectory() + "/tc/"); FilesInFolder = GetFiles(folder.getAbsolutePath()); //Toast.makeText(this, FilesInFolder.toString(), 2000).show(); for (int i = 0; i &lt; *WHATEVER NUMBER OF FILES*.length(); i++) { // //imageArry.add(new Contact(R.drawable.ic_launcher, FILENAME(FROM GETFILES()), FILEMODIFIED DATE(FROM GETFILELM()))); } Toast.makeText(this, Integer.toString(j), 2000).show(); // add image and text in arraylist imageArry.add(new Contact(R.drawable.ic_launcher, "FaceBook", "8/2/2013")); // take this out imageArry.add(new Contact(R.drawable.ic_launcher, "Google", "8/2/2013")); // take this out // add data in contact image adapter adapter = new ContactImageAdapter(this, R.layout.list, imageArry); ListView dataList = (ListView) findViewById(R.id.list); dataList.setAdapter(adapter); } public ArrayList&lt;String&gt; GetFiles(String DirectoryPath) { ArrayList&lt;String&gt; MyFiles = new ArrayList&lt;String&gt;(); File f = new File(DirectoryPath); //f.mkdirs(); 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(".")); MyFiles.add(fileName); //MyFiles.add(files[i].getName()); if extension is also needed } } } return MyFiles; } public ArrayList&lt;String&gt; GetFileLM(String DirectoryPath) { ArrayList&lt;String&gt; MyFiles = new ArrayList&lt;String&gt;(); File f = new File(DirectoryPath); //f.mkdirs(); 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 dateString = DateFormat.format("MM/dd/yyyy", new Date(lastTime)).toString(); MyFiles.add(dateString); } } } 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>I just need some help for the following lines: Instead of using the following line which enters data manually:</p> <pre><code>imageArry.add(new Contact(R.drawable.ic_launcher, "FaceBook", "8/2/2013")); // take this out </code></pre> <p>I would like to accomplish the following:</p> <pre><code>for (int i = 0; i &lt; *number of files in the folder*.length(); i++) { // //imageArry.add(new Contact(R.drawable.ic_launcher, FILENAME(FROM GETFILES()), FILE MODIFIED DATE(FROM GETFILELM()))); } </code></pre> <p>Replace <code>"FaceBook"</code> with the <code>FileName()</code> and <code>"8/2/2013"</code> with <code>GetFileLM()</code> and use a loop so the loop can enter as many files available from the <code>tc</code> using <code>imageArry.add();</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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