我想從URL中讀取文本文件,解析並設置一個arraylist,然後將其添加到我的適配器。然而,每當我嘗試啓動應用程序,我發現我的信息arraylist沒有填充數據。我想知道如何讓應用程序從URL讀取數據並顯示它。在互聯網中,我確實擁有對執行者的承諾。Android從URL中讀取文本文件並設置arraylist
CardAdapter ca = new CardAdapter(createList(0));
recList.setAdapter(ca);
ArrayList<CardInfo> infos = new ArrayList<CardInfo>();
try {
URL url = new URL("https://dl.dropboxusercontent.com/u/56230108/events.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line = "";
while ((line = br.readLine()) != null) {
Log.e("value", line);
String[] a = line.split("\\$EV\\$");
CardInfo info = new CardInfo();
info.title = a[0];
info.desc = a[1];
info.date = a[2];
info.time = a[3];
info.contact = a[4];
infos.add(info);
}
br.close();
}
catch(Exception e)
{
}
if(infos.size() > 0)
{
ca.add(infos.get(0), 0);
}
問題是我甚至無法讀取URL,我沒有得到任何數據輸入 – NexusOnly 2014-11-23 04:56:40