问题描述
结果
我刚开始学习Android的节目。我有我希望有人能帮助解决的一个问题。
它是:
我有一个的ListView
和文本文件名为 contact.txt
在下面的内容:
I have just started studying android programming. I have a problem that I hope someone can help to solve it.it is:I have a ListView
and a text file name is contact.txt
with content in below:
John Mesk,0155044932<br>
Lisa Mohamlise,0155044932<br>
Behney Comus,055653333<br>
如何从它的数据加载到的ListView
?我保存的文本文件,可绘制/ contact.txt结果
感谢您的阅读!
how to load data from it into ListView
? I saved the text file to drawable/contact.txt
Thank you for reading!
推荐答案
我有你的资料
要读取的文件,以string..there从 1
To read the file to string..there are soo many ways from 1
字符串文本=新的扫描仪(新文件(contact.txt)).useDelimiter(\\\\ A)和Next();
为 2 共享 FileUtils.readFileToString ,也是你去做的 3
to 2 Commons FileUtils.readFileToString, and also you go do 3
static String readFile(String path, Charset encoding)
throws IOException{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
或者更好的是,你可以把时间在换行或换行,并做一些华而不实一个像这样的 4
List<String> contacts = Files.readAllLines(Paths.get(path), encoding);
更多的这里
字符编码 = StandardCharsets.UTF_8
所以要根据您的选择,实现其中之一。为说明我用的是最后一个,因为我得到了我行我做了一些华而不实一个像这样
so depending on your choice, implement one of them. for illustrations i use the last one, and since i got my lines i do some slick one like this
Listview.setAdapter(new ArrayAdapter<String>(Context,yourResourcelayout, contacts));
是的,我认为是做..让我知道,如果它有帮助
yeah i think is done.. let me know if its helpful
这篇关于从文本文件导入的ListView加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!