0

I will be having large text files (privacy statements, etc, probably no more than 100k) and I'd like to have them in either /assets or /raw folder, not in my @strings file.

Also, I'd like to load them in a text view from the xml, I know I can do it programmatically.

One way I know of is to extend the text view and declare a stylable attribute, parse it and do the stuff I need from the code behind.

But is there a native way in android to do that? Without me having to write the logic for it? It doesn't look like an uncommon case.

George
  • 3,727
  • 9
  • 31
  • 47
  • 3
    AFAIK It is not possible but You can place the text in Strings.xml,no matter how large is your text size – Pragnani Mar 13 '13 at 10:13
  • Well, considering all things, I concluded a special resource xml file for every big text file(terms, privacy) would be a good enough approach - easily internationalizable and not obstructing or flooding the main strings.xml file. – George Mar 13 '13 at 13:19

1 Answers1

0

To display file contents you can do it like this:"Codes" is a name of the directory and FILE_RECEIVE is name of file to be opened.

  InputStream ss;
    String code;
    String content = "";
    try{
        files = assetManager.list("Codes");
        ss=getAssets().open("Codes/"+FILE_RECEIVE);
        content= convert_to_String(ss);
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }



public String convert_to_String(InputStream ss)
{

    BufferedReader bufferedReader=null;
    StringBuilder stringBuilder=new StringBuilder();
    String line;
    try{
        bufferedReader= new BufferedReader(new InputStreamReader(ss));
        while ((line=bufferedReader.readLine())!=null)
        {    stringBuilder.append("\n");
            stringBuilder.append(line);
        }
    }catch (IOException e){
        e.printStackTrace();
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return  stringBuilder.toString();

}
Akshay Patel
  • 85
  • 10