我在sl4a
寻找一个简单的文件选择器对话框。我找到了一些原生对话here,但找不到我要找的那个。
我希望通过找到随时可用的东西来节省时间。像filename = fileopendialog()
这样的最小代码就是奖金。
有什么想法吗?
答案 0 :(得分:0)
我决定自己编写(参见下面的参考资料)。这可能会更好,欢迎任何建议。
import android, os, time
droid = android.Android()
# Specify root directory and make sure it exists.
base_dir = '/sdcard/sl4a/scripts/'
if not os.path.exists(base_dir): os.makedirs(base_dir)
def show_dir(path=base_dir):
"""Shows the contents of a directory in a list view."""
#The files and directories under "path"
nodes = os.listdir(path)
#Make a way to go up a level.
if path != base_dir:
nodes.insert(0, '..')
droid.dialogCreateAlert(os.path.basename(path).title())
droid.dialogSetItems(nodes)
droid.dialogShow()
#Get the selected file or directory .
result = droid.dialogGetResponse().result
droid.dialogDismiss()
if 'item' not in result:
return
target = nodes[result['item']]
target_path = os.path.join(path, target)
if target == '..': target_path = os.path.dirname(path)
#If a directory, show its contents .
if os.path.isdir(target_path):
show_dir(target_path)
#If an file display it.
else:
droid.dialogCreateAlert('Selected File','{}'.format(target_path))
droid.dialogSetPositiveButtonText('Ok')
droid.dialogShow()
droid.dialogGetResponse()
if __name__ == '__main__':
show_dir()