Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was solving the same problem.</p> <ol> <li><p>Extend your list row with some <code>ImageView</code> where you will set the icon. Example file_row.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:textAppearanceLarge" android:layout_toRightOf="@id/icon"/&gt; &lt;/RelativeLayout&gt; </code></pre></li> <li><p>Fill <code>ArrayAdapter</code> with items like <code>File</code> or something from which information <code>isDirectory()</code> and <code>getFileName()</code> can be obtained.</p></li> <li><p>(optional) Sort the adapter items with comparator comparing them to left dirs on top. Method <code>Adapter.sort(Comparator)</code></p></li> <li><p>In your <code>getView(int, View, ViewGroup)</code> method in ArrayAdapter do something like this.</p> <pre><code> @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.file_row, null); } FileItem item = getItem(position); TextView nameTextView = (TextView)convertView.findViewById(android.R.id.text1); nameTextView.setText(item.getFileName()); ImageView imageView = (ImageView)convertView.findViewById(R.id.icon); if (item.isDirectory()) { imageView.setImageResource(R.drawable.directory); } else { imageView.setImageResource(R.drawable.file); } return convertView; } </code></pre></li> </ol> <p>Of course you can do some more sophisticated stuff like setting different icon for each file type, setting thumbnails etc. But the principle will be similar.</p>
    singulars
    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.
 

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