0

I post this message because i have a problem with my Android application.

When my application is starting, a function searchs all files which are presents in a folder. This function return an ArrayList which contain the name of all files.

I want modified my activity view to show up all of the files but I don't know how it's possible, so if someone can help me...

Thank you

boboch
  • 63
  • 2
  • 7

2 Answers2

0

Without code it's difficult to respond. However if you have got a view with an Adapter (ArrayAdapter for example) when you load the data in the array you can call notifyDataSetChanged().

other stackoverflow post

Community
  • 1
  • 1
greywolf82
  • 21,813
  • 18
  • 54
  • 108
0

First if you already have a ListView in your activity that you just want to update call this method after data changed notifyDataSetChanged()

if not you need to add a Listview into your activity and publish your list of string into it via ArrayAdapter

Simple example:

 // create a new file
        File file = new File("yourPath");

        //get the file list in an array of file
        File[] fileList = file.listFiles();

        //create a list of string that will store all file name

        List<String> fileNameList = new ArrayList<String>();
        //get all names
        for(int i= 0; i<fileList.length; i++){

            fileNameList.add(fileList[i].getName());
        }

        //I know you already have a list of file name it just to be a bit more clear... now publish the result into your listView
        myListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,fileNameList));
murielK
  • 1,000
  • 1
  • 10
  • 21