androidlistviewandroid-internal-storage

How to display specific file on the internal storage in listview android?


I saved some file in my app now I want to show the ones which are ended by .txt on my listview not all of them. Could you please help me?

You can see all files in my screenshot, I want to show just .txt ones

Here is how I generated my listview:

void ShowSavedFiles(){
    SavedFiles = fileList();

    ArrayAdapter adapter = new ArrayAdapter<String>(this,
                                  android.R.layout.simple_list_item_1,
                                  SavedFiles);

    listSavedFiles.setAdapter(adapter);
}

Solution

  • Here is the solution:

    void ShowSavedFiles(){ArrayList<String> filteredList = new ArrayList<String>();
    SavedFiles = fileList();
    
    for(String str: SavedFiles) {
        if (str.trim().contains("_cred.txt")) {
                      filteredList.add(str.trim());}
         }
               ArrayAdapter adapter
                    = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1,
                    filteredList);
    
            listSavedFiles.setAdapter(adapter);}