Search code examples
javaandroidandroid-dialogcharsequence

Set charsequence size after declaration


Ok, so I have something like:

CharSequence[] lines;

and then I want to set its size in an Android Dialog click, like:

lines = new CharSequence[131];

but it will end up empty.

I need to populate a dialog with its values, but if I would do something like:

CharSequence[] lines = new CharSequence[131];

in the beginning and then populating it, then I will get an error when scrolling because of the null options in the dialog (no of options < 131).

I am kind of a beginner in Java. Any help would be appreciated.


Solution

  • Two options:

    1. You check when a cell is empty lines[i] != null
    2. You fill lines with data using Arrays.fill(lines, new CharSequence()) see the doc