_filePicker.setTitle("Choose file");
// Initialize a check box for toggling the file filter
final CheckboxField checkBox =
new CheckboxField("Filter", false, Field.FIELD_HCENTER);
checkBox.setChangeListener(new FieldChangeListener() {
/**
* @see FieldChangeListener#fieldChanged(Field, int)
*/
public void fieldChanged(final Field field, final int context) {
if (checkBox.getChecked()) {
// Set the FilePicker to filter by extension
FilePickerDemoScreen.this.setFilter(true);
_filterTextChoiceField.setEditable(true);
_viewChoiceField.setSelectedIndex(0);
_viewChoiceField.setEditable(false);
} else {
// Disable the filter
FilePickerDemoScreen.this.setFilter(false);
_filterTextChoiceField.setEditable(false);
_viewChoiceField.setEditable(true);
}
}
});
add(checkBox);
// Add a choice field for specifying file filter type
String[] choices = new String[] { "All", "MP3", "JPG", "MPG" };
_filterTextChoiceField =
new ObjectChoiceField("Filter extension: ", choices, 0);
add(_filterTextChoiceField);
_filterTextChoiceField.setChangeListener(new FieldChangeListener() {
/**
* @see FieldChangeListener#fieldChanged(Field, int)
*/
public void fieldChanged(final Field field, final int context) {
FilePickerDemoScreen.this.setFilter(true);
}
});
_filterTextChoiceField.setEditable(false);
// Initialize a choice field for highlight style selection
choices =
new String[] { "Default", "Pictures", "Ring Tones",
"Music", "Videos", "Voice Notes" };
_viewChoiceField =
new ObjectChoiceField("View: ", choices,
FilePicker.VIEW_ALL);
_viewChoiceField.setChangeListener(new FieldChangeListener() {
/**
* @see FieldChangeListener#fieldChanged(Field, int)
*/
public void fieldChanged(final Field field, final int context) {
// Change the view type for the FilePicker
final int index = _viewChoiceField.getSelectedIndex();
switch (index) {
case FilePicker.VIEW_ALL:
_filePicker.setTitle("Choose file");
_filePicker.setView(FilePicker.VIEW_ALL);
break;
case FilePicker.VIEW_PICTURES:
_filePicker.setTitle("Choose picture");
_filePicker.setView(FilePicker.VIEW_PICTURES);
break;
case FilePicker.VIEW_RINGTONES:
_filePicker.setTitle("Choose ringtone");
_filePicker.setView(FilePicker.VIEW_RINGTONES);
break;
case 3:
_filePicker.setTitle("Choose music");
_filePicker.setView(FilePicker.VIEW_MUSIC);
break;
case 4:
_filePicker.setTitle("Choose video");
_filePicker.setView(FilePicker.VIEW_VIDEOS);
break;
case 5:
_filePicker.setTitle("Choose voice note");
_filePicker.setView(FilePicker.VIEW_VOICE_NOTES);
break;
}
}
});
add(_viewChoiceField);
add(new SeparatorField());
// Add a button to display the FilePicker
_buttonField =
new ButtonField("Choose File", Field.FIELD_HCENTER
| ButtonField.CONSUME_CLICK);
_buttonField.setChangeListener(new FieldChangeListener() {
/**
* @see FieldChangeListener#fieldChanged(Field, int)
*/
public void fieldChanged(final Field field, final int context) {
_filePicker.show();