-2

我正在研究可搜索的字典。它使用 SQLite 数据库。字典格式如下(2 列用“-”分隔)

Apple - One kind of fruit
Cricket - One type of game
Titanic - One type of Movie

Apple是列AOne kind of fruit是列B

我已经更新了我的数据库,如下所示

Apple - res/raw/Apple.txt
Titanic- res/raw/Titanic.txt

我想Apple.txt在用户搜索时打开文件并显示文本Apple。但我使用的示例代码仅适用于 TextView,而不是打开文件、缓冲区和 ViewText。

这是我的代码,它在我的应用程序中显示 B 列

TextView details = (TextView) findViewById(R.id.details);
details.setMovementMethod(new ScrollingMovementMethod());

请建议我如何通过替换上述代码从搜索查询中打开 Apple.txt?

[发布更新]

4

1 回答 1

1

您可以根据以下内容使用拆分-

String[] res = line.split("\\s+-\\s+");

现在你会有类似的东西:

[Apple, One kind of fruit]

现在,因为您Apple在 A 列中有,所以您知道必须显示 的位置apple.txt

或者(更好的方法),您可以将路径存储在 B 列中,如评论中所述的@Egor:

Apple - the_path_to_open.txt

现在,当您拆分时,您将在数组的第一个元素(即 B 列)中获得路径,您可以打开它以显示其结果。

于 2013-04-21T07:41:55.587 回答