0

I'm a beginner and I would like to ask why is this code not working?

I'm trying to achieve how to open *.txt files at option in assets subdirectory.

mTopicOneList = new ArrayList(Arrays.asList(getResources().getStringArray(R.array.topic_one)));

ListView list = (ListView) findViewById(R.id.topic_one_list);
list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View view,
                                int position, long id) {
            intent = new Intent(view.getContext(), TextActivity.class);
            AssetManager assetManager = getApplicationContext().getAssets();
            InputStream input;
            String assetsString;

            try {

                String[] subDirectoryFileList = assetManager.list("topicone/");
                input = assetManager.open(subDirectoryFileList[position]);

                int size = input.available();
                byte[] buffer = new byte[size];
                input.read(buffer);
                input.close();

                assetsString = new String(buffer);
                intent.putExtra("textFromAssets",assetsString);

            } catch (IOException e) {
                e.printStackTrace();
            }
            startActivity(intent);
        }

});  
dgilperez
  • 10,716
  • 8
  • 68
  • 96
3888
  • 11
  • 3
  • Define "not working" – motoDrizzt Feb 16 '15 at 09:29
  • Answer of user "andro" http://stackoverflow.com/users/1785200/andro This solution seems working for me: Keep a copy of each file you want to access from a sub directory in the assets directory too. Use same convention. i.e. list("subdirectory") It doesn't read the files in assets folder, but reads all "copied" files in its sub directory. Weird!! But works! http://stackoverflow.com/questions/3631370/list-assets-in-a-subdirectory-using-assetmanager-list Question is closed. – 3888 Feb 16 '15 at 15:28

0 Answers0