简体   繁体   English

搜索资产文件夹

[英]Search through asset folder

I want to make an app with 2 html files at my asset folder: one.html and two.html Then when some body type in my edittext: one, it opens the one.html. 我想制作一个在我的资产文件夹中有2个html文件的应用程序:one.html和two.html然后在我的edittext中输入某些正文时,它会打开one.html。

Is that possible and how can i do that. 那可能吗,我该怎么做。 I have this code but i don't now what to do with it: 我有以下代码,但现在不知道如何处理:

AssetManager assetManager = getAssets();
String[] files = null;
try {
    files = assetManager.list("");
} catch (IOException e) {
    Log.e("Error loading assets", e.getMessage());
}
for (String file : files) {
    if (file.equals("one.html")) {
        Open the html with webview
    else if (file.equals("two.html")) {
        Open the html with webview
}
}

So do you now how i can search trough my asset folder with an EditText ? 那么,您现在如何使用EditText资产文件夹中搜索呢?

I don't understand why you say "with an EditText " but placing files in the asset folder means you can read through them using java's File class. 我不明白为什么您说“带有EditText ”,但是将文件放置在资产文件夹中意味着您可以使用Java的File类通读它们。

Just google for a tutorial on how to search files through directories, here are two of them: 只是谷歌谷歌有关如何通过目录搜索文件的教程,这里有两个:

create one edittext and one webview. 创建一个edittext和一个webview。 if you write file name in edit text then your webview will load the file from assets folder and show it 如果您在编辑文本中输入文件名,则您的网络视图将从资产文件夹中加载文件并显示

Sudo code 须藤代码

String str = editText.getText().toString() +".html"
webview.loadUrl("file:///android_asset/"+str);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM