开发者

ArrayList<File>() as a Spinner

开发者_StackOverflowI have an ArrayList() that I want to display as a Spinner. Problem is, I need to display something other than the File.toString(). I would like to set the Spinner's view text to the file name (formatted), not the full file path returned by File.toString(), so I believe this rules out just using ArrayAdapter? Thanks!


Android SDK docs for ArrayAdapter recommend the following:

Override the toString() method of your objects to determine what text will be displayed for the item in the list.

Which means you can still use ArrayAdapter, but you would need to create a wrapper object which contains your true File eg FileFormat which overwrites toString() with your desired format.

class FileFormat {
    private File delegate;
    FileFormat (File delegate) {
       this.delegate = delegate;
    }
    public String toString() {
       return formatAllPrettyAndWhatNot (delegate);
    }
};
//then use a ArrayList<FileFormat>(), in your array spinner adapter 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜