代码之家  ›  专栏  ›  技术社区  ›  Will Brian Hodge

作为微调器的ArrayList

  •  1
  • Will Brian Hodge  · 技术社区  · 15 年前

    我有一个ArrayList()要显示为微调器。问题是,我需要显示除File.toString()之外的其他内容。我想将微调器的视图文本设置为文件名(格式化),而不是file.toString()返回的完整文件路径,所以我认为不必只使用ArrayAdapter?谢谢!

    1 回复  |  直到 15 年前
        1
  •  2
  •   Akusete    15 年前

    Android SDK文档 ArrayAdapter 建议如下:

    也就是说你仍然可以使用 ArrayAdapter FileFormat 覆盖 toString() 你想要的格式。

    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