Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6730059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:21:47+00:00 2026-05-26T10:21:47+00:00

===EDIT=== Is there a reason something like this doesn’t work i feel like it

  • 0

===EDIT===

Is there a reason something like this doesn’t work i feel like it should but it won’t work lView.getChildCount() returns 0 even though there is a lot in the list and then this causes a force close

for (int i = 0; i < lView.getChildCount(); i++) {
   ImageView imageView = (ImageView) lView.getChildAt(i).findViewById(R.id.listIcon);
   imageView.setImageResource(R.drawable.someIcon);
}

==================================

First i know you can make custom adapters and all i’m just thinking for my purposes since this is a simple file browser nothing advanced maybe this can be done.

Anyway like i said I’m working on a very simple file browser for part of an app i’m writing. I set it up to show all the files in a directory and have an icon next to it. The icon at the moment is the same for each file but i would like to have an icon for each type of file (ie zips, folders, scripts, etc)

What i would like to do is after the array and all has been made just do like for each position check the item and if it ends in say .zip change the icon something along the lines of this

for(eachposition){
   if(position.endsWith(".zip"){
      ImageView iv = (ImageView) findViewById(R.id.listIcon);
      iv.setImageResource(R.drawable.zipImage);
   }else if(position.endsWith(".sh"){
      ImageView iv = (ImageView) findViewById(R.id.listIcon);
      iv.setImageResource(R.drawable.scriptImage);
   }else{
      ImageView iv = (ImageView) findViewById(R.id.listIcon);
      iv.setImageResource(R.drawable.generalImage);
   }
}

anyway here is the code i’m using currently just in case this is needed and thank you for any help or input

public class SampleList extends ListActivity {

    private List<String> item = null;
    private List<String> path = null;
    private String root = "/sdcard/somefolder/";
    private String current = null;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        context = getApplicationContext();
        try{
            getDir(root);
            File directory = new File(root);
            File[] contents = directory.listFiles();
            if (contents.length == 0) {
                TextView t = new TextView(this); 
                t=(TextView)findViewById(R.id.empty); 
                t.setText(R.string.emptyFol);
            }
        }catch (Exception e) {
            Toast.makeText(NandPicker.this, R.string.nMount, Toast.LENGTH_LONG).show();
        }
    }

    private void getDir(String dirPath){
        item = new ArrayList<String>();
        path = new ArrayList<String>();

        File f = new File(dirPath);
        File[] files = f.listFiles();

        for(int i=0; i < files.length; i++){
            File file = files[i];
            //Problem was adding the path without the /
            //path.add(file.getPath());
            if(file.isDirectory()){
                path.add(file.getPath()+"/");
                item.add(file.getName() + "/");
            }else{
                path.add(file.getPath());
                item.add(file.getName());
            }
        }

        current = dirPath;

        ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.row, R.id.rowTextView, item);
        setListAdapter(fileList);
        class IgnoreCaseComparator implements Comparator<String> {
            public int compare(String strA, String strB) {
                return strA.compareToIgnoreCase(strB);
            }
        }
        IgnoreCaseComparator icc = new IgnoreCaseComparator();
        java.util.Collections.sort(path,icc);
        java.util.Collections.sort(item,icc);
    }

    @Override
    protected void onListItemClick(ListView l, View v, final int position, long id) {

    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:21:48+00:00Added an answer on May 26, 2026 at 10:21 am

    Take a look at an example here. This is covered quite often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't even know if I am doing this query the right way. There
Is there a (roughly) SQL or XQuery-like language for querying JSON? I'm thinking of
I would like a way to update my password on a remote Ubuntu 10.4
Is this illegal/dangerous? int* static_nonew() { static int n = 5; return &n; }
The manual on extract shows you can extract an array like: extract(array('one'=>1,'two'=>2)); into $one,$two...
I wonder if C# (or the underlying .NET framework) supports some kind of generic
So I'm working on a framework-esque system with one of my co-workers. Our current
Can anyone explain to me why java allows you to access static methods and
I have my server's apache configured to redirect every request into index.php, so that
I've got a very simple line of code in Objective-C: if ((selectedEntity != nil)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.