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
精彩评论